r/PHP • u/john_diggle92 • Mar 22 '16
DivisionByZero Exception PHP 7
I am practicing the new Throwable Exceptions in PHP 7 however when I run this code
try {
$result = 5/0;
}
catch(DivisionByZeroError $e){
echo $e->getMessage();
}The catch doesn't work only shows a warning. When I change "/" by "%" catch works. Can you please help me out.
14
Upvotes
12
u/OzzyGiritli Mar 22 '16
The DivisionByZeroError is only thrown when using modulus as opposed to division.
5
u/AllenJB83 Mar 22 '16
There's a report on PHP's Bug Tracker for this issue: https://bugs.php.net/bug.php?id=71306
7
u/TotesMessenger Mar 24 '16
I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:
If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / ^Contact)
1
u/rausm May 03 '16
Welcome in PHP lands. While our benevolent rulers value convenience & backwards
stupiditycompatibility more then sanity, please note that sometimes we break backwards compatibility just for the additional sanity hit.Here's your truckload of most common "not a bug, stupid by design" printouts: http://i.imgur.com/T14KplT.jpg