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 | 7 Comments »

7 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. Study in United States of America Says:
    September 1st, 2023 at 08:49

    Study in United States of America is a dream for many international students, and for good reason. It offers a wide range of programs and degrees across various fields, providing students with access to top-notch education and research opportunities. International students from all backgrounds are welcomed, and you’ll have the chance to interact with people from around the world, broadening your cultural horizons.

  6. Assignment Help Birmingham Says:
    September 19th, 2023 at 01:47

    I am Thomas Smith, and I have worked with Native Assignment Help UK for the past three years. Assignment Help Birmingham, proudly brought to you by Native Assignment Help UK, is your academic lifeline in the vibrant city of Birmingham. Our dedicated team of experts specializes in providing tailored solutions, delivering high-quality, plagiarism-free assignments that align with your specific academic requirements. With a steadfast commitment to academic excellence and integrity, we’re your trusted partner on the path to success in Birmingham’s educational landscape.

  7. Brock Hudson Says:
    September 22nd, 2023 at 02:47

    At Native Assignment Help, we take pride in being your trusted partner in the world of academia. With a strong commitment to excellence, our programming assignment help services stand out as the beacon of support for students seeking top-notch assistance in their programming coursework. Whether it’s Java, Python, C++, or any other programming language, we’ve got you covered.