PHP program to handle modulo by zero exception

Here, we will figure out how to deal with an exemption modulo by zero which happens when we partition (utilizing the modulus administrator to discover leftover portion) a number by 0?

The modulo by zero mistakes” tosses when we partition a number by zero to get the rest of modulus administrator (%).

It tends to be dealt with by utilizing “try…catch” articulation, with DivisionByZeroError special case.


    $a = 10;
    $b = 3;
        //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... ");


result: 1
Exception... Modulo by zero

Leave a Comment

error: Alert: Content is protected!!