exceptions during __toString()
| From: | Rasmus Schultz | Date: | Thu, 09 May 2013 22:00:23 +0000 |
| Subject: | exceptions during __toString() | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-67381@lists.php.net to get a copy of this message | ||
I just ran into this issue again:
http://stackoverflow.com/questions/2429642/why-its-impossible-to-throw-exception-from-tostring
Instead of throwing some nonsense "you're not allowed to throw from here"
error-message, how about actually unwinding the stack and passing the
exception to the global exception-handler?
I understand there's a technical limitation making it difficult/impossible
to handle exceptions during __toString() - and it looks like you can still
try {...} catch (Exception $e) in __toString() just fine, but then what?
You have the exception, but you have no way to pass it to the standard
global exception-handler.
If the script has to terminate either way, why not terminate the same way
an unhandled exception would normally cause the script to terminate?
E.g. output the actual error-message, or pass it to whatever was registered
with register_exception_handler() so it can be output or handled in the
usual way?