Quick question before submitting a feature request...

php.internals

Ken Stanley

18 years ago
Hello, I have done my best to look through both the internals archive and the bug database, however I feel that I may have missed something; hence this e-mail. I am working on a project that uses set_exception_handler() so that I can attempt to display a uniform error page, perform logging, etc, of exceptions. Due to prior lack of expertise on my part, I fool-heartedly wrote a view class that would throw an exception if a view was not found. The problem that I run into, that I feel could be improved, is that if the view class throws the exception during exception handling, I get the error, "Fatal error: Exception thrown without a stack frame in Unknown on line 0." Now, I completely understand and agree with why this is happening. I have corrected my mistake so that it will use trigger_error() instead of throwing an exception. However, in my Google searches I have noticed that there are a lot of people having somewhat similar problems, but without an easy solution. My feature request would be to include the filename and possibly even the line number where this last exception was thrown from. Since I am not using the bleeding edge version of PHP (I use 5.2.1), and I am not fluent in reading C, I was hoping someone here could let me know if this has already been fixed in a newer version of PHP, and if not, if it would be worth creating a feature request for this little bit of extra information. Is it even possible? I make the assumption that since the error states that it has no stack, then that would mean there is no information at all. Is that correct? Thank you for your time, and thank you for PHP. P.S. I did find bug #31304, which it seems the submitter was poorly attempting to request this same thing. I admit that I do not use the bug tracker tool very much, so I am unsure if I should re-open this bug and just append my request to it, or create a new one that is worded more clearly. Please advise.
-- It looked like something resembling white marble, which was probably what it was: something resembling white marble. -- Douglas Adams, "The Hitchhikers Guide to the Galaxy"

Alexey Zakhlestin

18 years ago
Well, just as there is set_exception_handler, there is set_error_handler function which probably does what you want. Another thing: what stops you from explicitly catching the exception using try/catch blocks? I believe that would solve most of your problems. set_exception_handler is really a "last hope" situation On 11/22/07, Ken Stanley <dohpaz@gmail.com> wrote:
> Hello, > > I have done my best to look through both the internals archive and the bug > database, however I feel that I may have missed something; hence this > e-mail. I am working on a project that uses set_exception_handler() so that > I can attempt to display a uniform error page, perform logging, etc, of > exceptions. Due to prior lack of expertise on my part, I fool-heartedly > wrote a view class that would throw an exception if a view was not found. > The problem that I run into, that I feel could be improved, is that if the > view class throws the exception during exception handling, I get the error, > "Fatal error: Exception thrown without a stack frame in Unknown on line 0." > > Now, I completely understand and agree with why this is happening. I have > corrected my mistake so that it will use trigger_error() instead of throwing > an exception. However, in my Google searches I have noticed that there are a > lot of people having somewhat similar problems, but without an easy > solution. My feature request would be to include the filename and possibly > even the line number where this last exception was thrown from. Since I am > not using the bleeding edge version of PHP (I use 5.2.1), and I am not > fluent in reading C, I was hoping someone here could let me know if this has > already been fixed in a newer version of PHP, and if not, if it would be > worth creating a feature request for this little bit of extra information. > Is it even possible? I make the assumption that since the error states that > it has no stack, then that would mean there is no information at all. Is > that correct? > > Thank you for your time, and thank you for PHP. > > P.S. I did find bug #31304, which it seems the submitter was poorly > attempting to request this same thing. I admit that I do not use the bug > tracker tool very much, so I am unsure if I should re-open this bug and just > append my request to it, or create a new one that is worded more clearly. > Please advise. > > -- > It looked like something resembling white marble, which was > probably what it was: something resembling white marble. > -- Douglas Adams, "The Hitchhikers Guide to the Galaxy" >
-- Alexey Zakhlestin http://blog.milkfarmsoft.com/

Antony Dovgal

18 years ago
On 22.11.2007 06:12, Ken Stanley wrote:
> I have > corrected my mistake so that it will use trigger_error() instead of throwing > an exception. However, in my Google searches I have noticed that there are a > lot of people having somewhat similar problems, but without an easy > solution. My feature request would be to include the filename and possibly > even the line number where this last exception was thrown from.
The execution phase is finished at the moment when exception handlers and shutdown functions are called. No script is executing -> no line & filename info anymore -> filename = Unknown, line = 0.
-- Wbr, Antony Dovgal

Ken Stanley

18 years ago
Anthony, thank you for your response. Would it not be possible that when an exception is thrown to temporarily store the filename/line number for when the exception handler kicks in, so at the very least, if someone made the mistake of throwing an exception inside of another exception, they could at least be told where to go to fix their mistake? I am only asking to this list because I would hate to submit a ticket that is just going to be closed. :) On Nov 23, 2007 1:09 PM, Antony Dovgal <tony@daylessday.org> wrote:
> On 22.11.2007 06:12, Ken Stanley wrote: > > I have > > corrected my mistake so that it will use trigger_error() instead of > throwing > > an exception. However, in my Google searches I have noticed that there > are a > > lot of people having somewhat similar problems, but without an easy > > solution. My feature request would be to include the filename and > possibly > > even the line number where this last exception was thrown from. > > The execution phase is finished at the moment when exception handlers and > shutdown functions are called. > No script is executing -> no line & filename info anymore -> filename = > Unknown, line = 0. > > -- > Wbr, > Antony Dovgal >
-- It looked like something resembling white marble, which was probably what it was: something resembling white marble. -- Douglas Adams, "The Hitchhikers Guide to the Galaxy"

Edward Z. Yang

18 years ago
Ken Stanley wrote:
> The problem that I run into, that I feel could be improved, is that if the > view class throws the exception during exception handling, I get the error, > "Fatal error: Exception thrown without a stack frame in Unknown on line 0."
This may be a documentation problem. set_exception_handler() is often touted as an easy way to define a global try/catch block, but it's not meant to call a complex View subsystem to render the error, after all, it occurs during the destructor phase. At the very least, the documentation should mention that throwing an exception from inside this handler will result in a fatal error. I think, however, it should actively encourage using a global try {} catch {} block. I understand this solution won't work if application Exceptions don't have a common parent class, but this is already recommended as a good practice.
-- Edward Z. Yang GnuPG: 0x869C48DA HTML Purifier <http://htmlpurifier.org> Anti-XSS Filter [[ 3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA ]]

Alexey Zakhlestin

18 years ago
On 11/23/07, Edward Z. Yang <edwardzyang@thewritingpot.com> wrote:
> I understand this solution won't work if application > Exceptions don't have a common parent class, but this is already > recommended as a good practice.
In PHP all exceptions have "Exception" as a parent-class
-- Alexey Zakhlestin http://blog.milkfarmsoft.com/

Edward Z. Yang

18 years ago
Alexey Zakhlestin wrote:
> In PHP all exceptions have "Exception" as a parent-class
Indeed you are right! Even better.
-- Edward Z. Yang GnuPG: 0x869C48DA HTML Purifier <http://htmlpurifier.org> Anti-XSS Filter [[ 3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA ]]