note 68712 added to function.set-exception-handler
| From: | mastabog at hotmail dot com | Date: | Tue, 08 Aug 2006 14:44:54 +0000 |
| Subject: | note 68712 added to function.set-exception-handler | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-115653@lists.php.net to get a copy of this message | ||
A behaviour not documented or discussed enough, yet pretty common is that is that if an exception is
thrown from the global exception handler then a fatal error occurs (Exception thrown without a stack
frame). That is, if you define your own global exception handler by calling set_exception_handler()
and you throw an exception from inside it then this fatal error occurs. It is only natural though,
as the callback defined by set_exception_handler() is only called on uncaught (unhandled) exceptions
so if you throw one from there then you get this fatal error as there is no exception handler left
(you override the php internal one by calling set_exception_handler()), hence no stack frame for it.
Example:
<?php
function myExceptionHandler (Exception $ex)
{
throw $ex;
}
set_exception_handler("myExceptionHandler");
throw new Exception("This should cause a fatal error and this message will be lost");
?>
Will cause a Fatal error: Exception thrown without a stack frame
If you skip/comment the set_exception_handler("...") line then the internal PHP global
handler will catch the exception and output the exception message and trace (as string) to the
browser, allowing you to at least see the exception message.
While it is a very good idea to always define your own global exception handler by using the
set_exception_handler() function, you should pay attention and never throw an exception from it (or
if you do then catch it).
Finally, every serious coder should use an IDE with debugging capabilities. Tracking down an error
like this becomes a trivial matter by using simple debugging "Step into" commands (I for
one recommend Zend IDE v5.2 at the moment of this writing). I have seen numerous messages on the
internet with people wondering why this message pops up.
Cheers
p.s. Other causes for this error which are somehow unrelated to this is when you throw an exception
from a destructor (the reasons behind that are similar though, the global handler might no longer
exist due to the php engine shutting the page down).
----
Server IP: 66.163.161.117
Probable Submitter: 82.231.160.66
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.set-exception-handler.php
Edit -- https://master.php.net/note/edit/68712
Del: integrated -- https://master.php.net/note/delete/68712/integrated
Del: useless -- https://master.php.net/note/delete/68712/useless
Del: bad code -- https://master.php.net/note/delete/68712/bad+code
Del: spam -- https://master.php.net/note/delete/68712/spam
Del: non-english -- https://master.php.net/note/delete/68712/non-english
Del: in docs -- https://master.php.net/note/delete/68712/in+docs
Del: other reasons-- https://master.php.net/note/delete/68712
Reject -- https://master.php.net/note/reject/68712
Search -- https://master.php.net/manage/user-notes.php