PHP program to demonstrate the finally block in exception handling

bookmark

<?php
// PHP program to demonstrate the finally block
// in exception handling.
try
{
    $A = 10;
    $B = 0;

    if ($B == 0) throw new Exception("Divide by Zero exception");
    $C = $A / $B;
    printf("Value of C: %d<br>", $C);
}
catch(Exception $e)
{
    printf("Exception: %s<br>", $e->getMessage());
}
finally
{
    printf("Finally block executed");
}
?>


Output
Exception: Divide by Zero exception
Finally block executed