On 06/03/2021 18:00, Larry Garfield wrote:
My first thought is that if you're throwing away exceptions, you're therefore
performing an expensive operation (generating a backtrace for the exception)
that will then be discarded, and thus is wasted effort.
I think regardless of any new syntax, this cost is something that needs
to be looked into if we want to use exceptions for anything but the most
extreme errors.
If I'm catching a FileAccessDeniedException, the details of every
framework function and middleware handler in my call stack probably
aren't relevant, so being able to skip that overhead would be great.
Would it be possible to build up the stack trace lazily, as the stack is
unwound? Then if ->getTrace() is called, grab the rest of the stack,
which will still be current anyway.
In my head, it would look something like this, only at the engine level
rather than an actual finally block:
try {
...
throw new Exception; // here, the current line number is captured,
but nothing else
...
}
finally {
// Save trace information for current frame before returning
}
Then further up the stack:
try {
something_that_throws();
}
catch ( Exception $e ) {
echo $e->getTraceAsString(); // trace is currently incomplete, but
the remaining levels are the trace of the current line anyway, so we can
put the cost here
}
Does that make any sense?
Regards,
--
Rowan Tommins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php