Compdigitec Labs

« | Home | »

Solving “Fatal error: Exception thrown without a stack frame in Unknown on line 0”

By admin | August 2, 2009

If you attempt to throw an exception from a PHP destructor or an PHP exception handler, your script will execute fine for the most part and then crash with the rather cryptic error message, “Fatal error: Exception thrown without a stack frame in Unknown on line 0“. This message is unfortunately very cryptic if you are trying to debug your code. This effect is further amplified due to a lack of PHP debuggers and you must instead resort to using various print_r()s and var_dump()s in order to debug the program. The error message in basic form means that you’ve thrown an exception where an exception cannot be thrown (leading to “no stack frame” – exception handlers and destructors do not have a stack frame. This instead results in this rather cryptic error message that does not include script locations or detailed error information).

Most often, the error will appear if you use an exception handler combined with an error reporting to exception handler by converting it to an ErrorException, then there a suddenly a whole new magnitude of ways to throw errors within the exception handle, especially if E_NOTICE, E_STRICT and/or E_WARNING errors are converted. This form most often occurs when you use variables without first initializing them. This error may be preventable by wrapping the exception handler within a try/catch block.

A second form of this error occurs when you attempt to throw an exception in a destructor. This is well documented in the PHP manual, but this can still be triggered if you accidentally throw an exception:

There is no exactly solid way to identify this type of error as you may not know exactly what your functions do. If you are throwing exceptions manually in your destructor, you need to go back to the PHP manually and read that it is not possible to throw exceptions within the destructor (as it lacks a stack frame). For the other two, you may need to comment out your destructors and manually uncomment parts until you reach the point where you find the error line as the error message produced by PHP is not too informative.

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles!

Topics: PHP | 5 Comments »

5 Responses to “Solving “Fatal error: Exception thrown without a stack frame in Unknown on line 0””

  1. Q Says:
    March 7th, 2010 at 10:54

    instead of commenting out your destructors, you might just wrap it inside a try-catch block, as the stack-frame only gets lost as soon as the exception is gets outside the destructor:


    function __destruct()
    your code
    catch(Exception $e)
    echo $e->__toString();

  2. [magento] PHP Fatal error: Exception thrown without a stack frame in Unknown on line 0 | Hosting Al Descubierto Says:
    July 8th, 2010 at 04:50

    […] Los manejadores de excepciones ‘ exception handlers‘ y los destructores no tienen ‘stack frame‘. Por lo que combinar por ejemplo un ‘execption handler‘ con un ‘error preporting‘  o lanzar un execption en un destructor puede provocar que aparezcan. Os podeis documentar más en este interesante enlace Solving “Fatal error: Exception thrown without a stack frame in Unknown on line 0″ […]

  3. Tomasz Says:
    September 23rd, 2011 at 16:58

    There is at least one more source of this error: throwing exception inside output callback registered in ob_start().

  4. rose Says:
    November 14th, 2012 at 11:45

    It’s hard to come by well-informed people for this subject, however, you seem like you know what you’re talking about!


  5. emergingstrategy Says:
    June 28th, 2024 at 12:43

    Research and consulting firms provide expert analysis and strategic advice across various industries, aiding businesses in decision-making and problem-solving. They conduct employing methodologies such as surveys, interviews, and data analysis to generate actionable insights. These firms play a crucial role in shaping market trends and informing corporate strategies through their comprehensive research capabilities and specialized knowledge.