Re: Throwable interface

php.internals

Stanislav Malyshev

23 years ago
SB>> The lack of a common interface of thrown exceptions hinders the SB>> development of applications like PHPUnit that need to be able to SB>> work with *every* possible exception. Don't we have a way to catch any exception in the language yet?
-- Stanislav Malyshev, Zend Products Engineer stas@zend.com http://www.zend.com/ +972-3-6139665 ext.109

Sterling Hughes

23 years ago
On Sun, 2003-03-23 at 10:24, Stanislav Malyshev wrote:
> SB>> The lack of a common interface of thrown exceptions hinders the > SB>> development of applications like PHPUnit that need to be able to > SB>> work with *every* possible exception. > > Don't we have a way to catch any exception in the language yet? >
If you want to catch any exception, just require people to define their exceptions as extending the "exception" class, if they wish to use phpunit. We shouldn't have an engine-level straightjacket on exceptions (more of a response to sebastian's mail than to stas'). -Sterling
> -- > Stanislav Malyshev, Zend Products Engineer > stas@zend.com http://www.zend.com/ +972-3-6139665 ext.109
-- "Whether you think you can or think you can't -- you are right." - Henry Ford

Wez Furlong

23 years ago
We need to do at least one of the following: 1) Force all exceptions to be descendants of a builtin Exception class 2) Force all exceptions to implement a Throwable interface 3) Provide a catch-all syntax to the language for exception handling. This is *extremely* important for people writing such things as SOAP or RPC servers that want to keep their implementations as robust as possible. While we are at it, lets have the call to undefined method fatal error and the type-hint checking raise exceptions too; procedural code will still bail out if it doesn't catch the exception, while robust OO coders will be able to act on the event and handle it gracefully. --Wez. On Sun, 23 Mar 2003, Sterling Hughes wrote:

Sebastian Bergmann

23 years ago
Wez Furlong wrote:
> This is *extremely* important for people writing such things as > SOAP or RPC servers that want to keep their implementations as > robust as possible.
I was thinking about those, too.
> While we are at it, lets have the call to undefined method fatal > error and the type-hint checking raise exceptions too; procedural > code will still bail out if it doesn't catch the exception, while > robust OO coders will be able to act on the event and handle it > gracefully.
Amen, Sebastian
-- Sebastian Bergmann http://sebastian-bergmann.de/ http://phpOpenTracker.de/ Did I help you? Consider a gift: http://wishlist.sebastian-bergmann.de/

Sterling Hughes

23 years ago
On Sun, 2003-03-23 at 10:33, Wez Furlong wrote:
> We need to do at least one of the following: > > 1) Force all exceptions to be descendants of a builtin Exception class > 2) Force all exceptions to implement a Throwable interface > 3) Provide a catch-all syntax to the language for exception handling. > > This is *extremely* important for people writing such things as SOAP or > RPC servers that want to keep their implementations as robust as > possible. > > While we are at it, lets have the call to undefined method fatal error > and the type-hint checking raise exceptions too; procedural code will > still bail out if it doesn't catch the exception, while robust OO coders > will be able to act on the event and handle it gracefully.
As mentioned over IRC. Why do this with Throwable (which raises the WTF factor), why not just add a generic default case: try { throw new Bar; } catch ($e) { // do stuff with the exception } sure introspection will suffer, but I'm against anything that forces a developer into a contract they may not want to make. -Sterling
-- "Science is like sex: sometimes something useful comes out, but that is not the reason we are doing it." - Richard Feynman

(Marcus Börger)

23 years ago
At 16:33 23.03.2003, Wez Furlong wrote:
>We need to do at least one of the following: > >1) Force all exceptions to be descendants of a builtin Exception class >2) Force all exceptions to implement a Throwable interface >3) Provide a catch-all syntax to the language for exception handling.
Coming from a c++ background i can see a reason for 3) but no real reason for any of the rest. marcus

Stanislav Malyshev

23 years ago
SH>> phpunit. We shouldn't have an engine-level straightjacket on SH>> exceptions (more of a response to sebastian's mail than to stas'). I meant something more to the lines of: try { } catch($e) { } where $e would catch any exception.
-- Stanislav Malyshev, Zend Products Engineer stas@zend.com http://www.zend.com/ +972-3-6139665 ext.109

Sebastian Bergmann

23 years ago
Stanislav Malyshev wrote:
> try { > } catch($e) { > } > > where $e would catch any exception.
This would even be constistent with the other class type hints. I could live with that, Sebastian
-- Sebastian Bergmann http://sebastian-bergmann.de/ http://phpOpenTracker.de/ Did I help you? Consider a gift: http://wishlist.sebastian-bergmann.de/

(Marcus Börger)

23 years ago
At 16:24 23.03.2003, Stanislav Malyshev wrote:
>SB>> The lack of a common interface of thrown exceptions hinders the >SB>> development of applications like PHPUnit that need to be able to >SB>> work with *every* possible exception. > >Don't we have a way to catch any exception in the language yet?
For me it sounds like Sebastian wants to write only one catch handler but that's not the point of designing with exceptions. Also the base class concept Sterling did is much more powerfull than an interface based concept. Simply because a user designed class cannot access the source information in such a good way than the base class can. marcus

Sebastian Bergmann

23 years ago
Marcus B?rger wrote:
> For me it sounds like Sebastian wants to write only one catch > handler but that's not the point of designing with exceptions.
No, that's not what I have in mind. The following is from PHPUnit/TestCase.php try { $this->runTest(); } catch (AssertionFailedError $e) { $this->result->addFailure($this, $t); } catch (Throwable $t) { $this->result->addError($this, $t); }
-- Sebastian Bergmann http://sebastian-bergmann.de/ http://phpOpenTracker.de/ Did I help you? Consider a gift: http://wishlist.sebastian-bergmann.de/