0

I don't understand why php code dosen't go to catch section? instead it's showing warning : Warning: Division by zero in C:\xampp\htdocs\test\test.php on line 3 INF

<?php
try{
    echo 5/0;
}catch(Exception $e){
    echo "Divide by 0 not allow.";
}
?>

Can anyone help how to manage this? There is so many question answer regarding this but can't find any perfect solution as c#, Java support try catch handling why php not following same standard?

  • https://stackoverflow.com/a/28281624/6444625 direct answer link – hungrykoala May 30 '18 at 05:50
  • @Tudor do you know answer why i have to throw manually? – Nishit Manjarawala May 30 '18 at 05:53
  • @NishitManjarawala because a warning and a exception are two different things. By default a warning does not interrupt script execution in terms of throwing anything you could catch. As of PHP 7 there is an an exception thrown (which you could catch) automatically tho (http://php.net/manual/en/class.divisionbyzeroerror.php). – Fabian S. May 30 '18 at 05:59

0 Answers0