Re: exceptions instead of errors

From: Date: Sun, 11 May 2003 15:00:37 +0000
Subject: Re: exceptions instead of errors
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-1440@lists.php.net to get a copy of this message
At 17:37 11/05/2003, Marcus Börger wrote:
At 16:23 11.05.2003, Derick Rethans wrote:
On Sun, 4 May 2003, Sterling Hughes wrote:
Just a note that I'd really like to see this. One of the great things about exceptions will be:
try { $m = mysql_connect("localhost", "user", "pass"); $sth = mysql_query("select bar from foo", $m); while ($row = mysql_fetch_array($sth)) {
    echo $row[0];
} mysql_close($m); } catch (exception $e) { echo $e->getMessage(); } This allows you to remove all the nasty if ($conn) could, and move your error handling into a singular place. I *really* would like this for internal functions. We could also make a new type of exception "internalexception," which a user has to specifically catch. This way unless you explictly specify that you want to catch an internalexception, it will default to just outputting an error message.
Sounds like a great idea to me!
Yes to me, too! I'll change my error2exception thingie to reflect your idea.
What do you have in mind? Sterling's description was actually one of the original reasons for introducing exceptions into PHP, at least from my point of view. But it's not very clear how exactly it can actually be implemented, because what we're dealing with here are warnings, not errors. There are probably ways to address this, but it's not trivial and should be discussed. Zeev

« previous php.internals (#1440) next »