Re: exceptions instead of errors
| From: | Daniel Lorch | Date: | Mon, 05 May 2003 10:59:55 +0000 |
| Subject: | Re: exceptions instead of errors | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-1253@lists.php.net to get a copy of this message | ||
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) {
> 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
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