NYCPHP Meetup

NYPHP.org

[nycphp-talk] If/else vs Try/catch

Michael Southwell michael.southwell at nyphp.com
Wed Nov 28 13:26:20 EST 2007


csnyder wrote:
> ... then try/catch is the way out of your nightmare.
> 
> try {
>   $obj->process1();
>   $obj->process2();
>   $obj->process3();
> } catch Exception( e ) {
>   exit( "An error occurred: ".$e->message() );
> }
> 
> Error handling doesn't need to be part of your program logic anymore.

Note that process1 etc must throw an exception internally in order for 
the catch to work, as explained once again at 
http://us2.php.net/manual/en/language.exceptions.php

-- 
=================
Michael Southwell
Vice President, Education
NYPHP TRAINING:  http://nyphp.com/Training/Indepth



More information about the talk mailing list