multiple catch block in php
Saturday, November 1, 2008 9:56Some time there is a need to catch more than one exception..In such a situation, we can associate more than one catch statement with a try, When an exception is thrown, the exception handlers are searched in order for an appropriate match. The first handler that yields a match is executed. After executing the handler, the control goes to the first statement after the last catch block for that try. When no match is found, the program is terminated.
$val = { 0, 2, 13, 0, 5, 6, 7, 8 };
for($i=0; $i < $val.length; $i++) {
try {
$k=$val[$i]/$i;
echo $k;
echo $val[$i+1];
}
catch (DivideByZeroException) {
// catch the exception
echo (“Can’t divide by Zero!”);
}
catch (IndexOutOfRangeException) {
// catch the exception
echo (“No matching element found.”);
}
}
When the try block does not throw any exception and when it completes normal execution, the control passes to the first statement after the last catch handler associated with that try bock.
we can have try block in catch block also... we can use nested try blocks..

