# Quick question before submitting a feature request...

- Thread: https://externals.io/message/33375
- Original archive: https://news-web.php.net/php.internals/33375
- Started by Ken Stanley on 2007-11-22T03:12:55+00:00
- Messages: 9
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #33375 — Ken Stanley — 2007-11-22T03:12:55+00:00

URL: https://externals.io/message/33375#33375

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"

---

## #33376 — Alexey Zakhlestin — 2007-11-22T07:38:58+00:00

URL: https://externals.io/message/33375#33376 · In reply to: #33375

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


> 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/

---

## #33380 — Ken Stanley — 2007-11-23T05:32:22+00:00

URL: https://externals.io/message/33375#33380

I completely agree with what you and Alexy suggest. I've since refactored my
code accordingly so that an exception would not be thrown while inside of an
exception. But, that does not answer my original question. I asked about
submitting a feature request that would simply provide more information in
the unfortunate event that anybody's code inadvertantly throws an exception
while in an exception, and whether or not it would be advantageous to do so,
or if work was already being done on this very issue.

The current error provides no information at all (e.g., no file name or line
number of the offending exception), which in some cases makes it nearly
impossible to debug. My apologies if I was not clear enough in my first
e-mail. :)


>
> Perfect code should catch every exception. If your code is at a point
> where exceptions can be thrown, you should be using catch to actually
> catch the exception and handle the exception appropriately.
>
> set_exception_handler should in fact only be used to spot a bug in your
> code.. A bug being in this case, not catching an expected exception. Its
> the last fallback.. If you really need complex code tied to your
> exception handler, then use a try..catch block there too..
>
> Evert
>



-- 
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"

---

## #33400 — Daniel Brown — 2007-11-23T17:49:42+00:00

URL: https://externals.io/message/33375#33400 · In reply to: #33380

Ken,

    This same issue was referred to back in 2004 on the php.net site.
I just looked it up and the post can be found by ptah@se.linux.org
from 9 September, 2004, on this page:
        http://us.php.net/errorfunc



> I completely agree with what you and Alexy suggest. I've since refactored my
> code accordingly so that an exception would not be thrown while inside of an
> exception. But, that does not answer my original question. I asked about
> submitting a feature request that would simply provide more information in
> the unfortunate event that anybody's code inadvertantly throws an exception
> while in an exception, and whether or not it would be advantageous to do so,
> or if work was already being done on this very issue.
>
> The current error provides no information at all (e.g., no file name or line
> number of the offending exception), which in some cases makes it nearly
> impossible to debug. My apologies if I was not clear enough in my first
> e-mail. :)
>
> 
> > […]
>
> > […]
>
>
>
> --
> 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"
>



-- 
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107

If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.

---

## #33401 — Antony Dovgal — 2007-11-23T18:09:24+00:00

URL: https://externals.io/message/33375#33401 · In reply to: #33375

> 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

---

## #33402 — Ken Stanley — 2007-11-23T20:36:24+00:00

URL: https://externals.io/message/33375#33402 · In reply to: #33401

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. :)



> 
> > […]
> throwing
> > […]
> are a
> > […]
> possibly
> > […]
>
> 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"

---

## #33403 — Edward Z. Yang — 2007-11-23T20:55:55+00:00

URL: https://externals.io/message/33375#33403 · In reply to: #33375

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 ]]

---

## #33404 — Alexey Zakhlestin — 2007-11-23T21:06:07+00:00

URL: https://externals.io/message/33375#33404 · In reply to: #33403

> 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/

---

## #33405 — Edward Z. Yang — 2007-11-23T21:16:34+00:00

URL: https://externals.io/message/33375#33405 · In reply to: #33404

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 ]]
