Re: exceptions instead of errors

From: Date: Mon, 05 May 2003 15:48:59 +0000
Subject: Re: exceptions instead of errors
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-1274@lists.php.net to get a copy of this message
some questions Daniel Lorch wrote:
hi,
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) {
Is "exception" class built in? if so, extendable by users? if not, how does getMessage() know where to find the error - especially if this error is produced by an extension.
echo $e->getMessage(); } This allows you to remove all the nasty if ($conn) could, and move your error handling into a singular place. [..]
Read more here: http://java.sun.com/docs/books/tutorial/essential/exceptions/definition.html
And reading the article, one can see that it relys on types to bubble up and be cought correctly.
Basically try/catch-statements allow you to keep the main code block short and readable because the error handling code is moved somewhere else. Would be nice seeing this in PHP. -daniel


« previous php.internals (#1274) next »