Bir try...catch bloğunda bir istisna atabilir işlev çağrısı (ler) kaydırmak gerekir.
class EvilException extends Exception {}
class BadException extends Exception {}
function someMethodThatMayThrowException() {
...
...
throw new EvilException( "I am an evil exception. HAHAHAHA" );
}
try {
someMethodThatMayThrowException();
} catch( BadException $e ) {
//deal with BadException here...
} catch( EvilException $e ) {
//deal with EvilException here...
throw new Exception( "will be caught in next catch block" );
} catch( Exception $e ) {
echo $e->getMessage(); //echoes the string: "will be caught in next catch block"
}
Eğer durum (lar) yakalamak ise, komut sona ermeyecektir. Fırlatılan bir durum içine atlamak için catch bloğu yoksa, yukarıda belirtilen olur.