PHP program to handle modulo by zero exception
<?php
$a = 10;
$b = 3;
try
{
//dividing $a by $b - no error
$result = $a%$b;
print("result: $result \n");
//assigning 0 to $b
$b = 0;
//now, dividing $a by $b - error occurs
$result = $a%$b;
print("result: $result \n");
}
catch(DivisionByZeroError $err){
print("Exception... ");
print($err->getMessage());
}
?>
Output
result: 1
Exception... Modulo by zero
