# Default exception handler

- Thread: https://externals.io/message/4394
- Original archive: https://news-web.php.net/php.internals/4394
- Started by marcus.boerger@t-online.de on 2003-09-05T15:24:21+00:00
- Messages: 3
- 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

---

## #4394 — marcus.boerger@t-online.de — 2003-09-05T15:24:21+00:00

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

Hello internals, hi Zeev, hi Andi,

  Currently php doesn't have a default exception handler that gets executed
if the thrown excpetion was not caught by any previous handler. I now
suggest the following extension:

try {
  // code
}
catch (class1 $var) {
}
catch (class2 $var) {
}
catch ($var) {
}

Thereby it should only be possible to have an exception handler that does
not specify a class as the last one. Since we only allow throwing objects at
the moment we know that the caught variable is any object and hence we do
not need a syntax like catch (...) provided by C++ for example.

An alternative concept would be to allow throwing exception instances only.
But inside the C code you could still throw other objects.

A patch to enable the new syntax can be found here:
http://marcus-boerger.de/php/ext/ze2/ze2-catch-20030905.diff.txt


Best regards,
 Marcus                          mailto:marcus.boerger@post.rwth-aachen.de

---

## #4409 — Andi Gutmans — 2003-09-06T05:32:15+00:00

URL: https://externals.io/message/4394#4409 · In reply to: #4394

Hi Marcus,

I implemented this functionality about a year ago (if I'm not mistaken it 
was part of the original ZE2 tree).
The reason we removed it (IIRC) was that we thought it would lead to 
cleaner PHP code and would force only objects being thrown (although this 
can be done in other ways).
I would like to keep things as-is because I think it's cleaner this way. 
Give the developer the benefit of the tought that he can design his 
Exception hierarchy in a good way, wether he inherits from our "Exception" 
class or from his own exception class.

Andi

---

## #4411 — Cristiano Duarte — 2003-09-06T16:02:03+00:00

URL: https://externals.io/message/4394#4411 · In reply to: #4409

Hi Andi,
IMHO I think there should be a way to catch all kinds of exceptions whether
they inherits from "Exception" or not. It's specially important in
standalone applications like those in PHP-GTK. An external library can throw
an unkown exception an it could terminate the program abnormally. Instead,
if we can catch this (at the moment) "unknown exception", maybe it would be
possible to recover the program stability.

Cristiano Duarte

"Andi Gutmans" <andi@zend.com> escreveu na mensagem
news:5.1.0.14.2.20030906082904.036cf2d0@127.0.0.1...
> Hi Marcus,
>
> I implemented this functionality about a year ago (if I'm not mistaken it
> was part of the original ZE2 tree).
> The reason we removed it (IIRC) was that we thought it would lead to
> cleaner PHP code and would force only objects being thrown (although this
> can be done in other ways).
> I would like to keep things as-is because I think it's cleaner this way.
> Give the developer the benefit of the tought that he can design his
> Exception hierarchy in a good way, wether he inherits from our "Exception"
> class or from his own exception class.
>
> Andi
