in reply to Re^3: Catching a 'division by zero' error with Exception::Class
in thread Catching a 'division by zero' error with Exception::Class
The important bit is that you are eval-ing the '27/0', but the "|| throw exception" part is outside the eval. So when the eval dies out of the execution and returns false, the exception is thrown.
The structure is eval {"risky expression"} or throw exception.
NOT eval {"risky expression; or throw exception"}
It should be noted that the return value of eval is:
"...the value of the last expression evaluated inside the mini-program; a return statement may be also used, just as with subroutines."So, you should add a "1;" or "return 1;" to the end, otherwise you would throw some spurious exceptions if the answer is supposed to be zero (such as 5*2-10)
|
|---|