PHP

How to demonstrate the Divide By Zero Exception using exception handling in PHP | PHP program

How to demonstrate the Divide By Zero Exception using exception handling in PHP | PHP program

How to demonstrate the Divide By Zero Exception using exception handling in PHP | PHP program

We will use try, catch, and throw keywords to demonstrate the DivideByZero exception in a PHP program.

<?php

try
{
    $A = 550;
    $B = 0;

    if ($B == 0) throw new Exception("Divide by Zero exception occurred");
    $C = $A / $B;

    printf("Value of C: %d<br>", $C);
}
catch(Exception $e)
{
    printf("Exception: %s", $e->getMessage());
}
?>
TutorialsLink Curator

This is an official account managed by the team TutorialsLink Community