PHP program to demonstrate the use of multiple catch blocks
<?php
// PHP program to demonstrate the use of multiple catch blocks.
class MyException extends Exception
{
}
try
{
$A = 10;
$B = - 1;
if ($B == 0) throw new MyException("Divide by Zero exception");
if ($B == - 1) throw new Exception("Negative exception");
$C = $A / $B;
printf("Value of C: %d<br>", $C);
}
catch(MyException $e)
{
printf("Exception: %s<br>", $e->getMessage());
}
catch(Exception $e)
{
printf("Exception: %s<br>", $e->getMessage());
}
?>
Output
Exception: Negative exception
