Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Catching a 'division by zero' error with Exception::Class

by moritz (Cardinal)
on Sep 15, 2008 at 15:45 UTC ( [id://711488]=note: print w/replies, xml ) Need Help??


in reply to Re: Catching a 'division by zero' error with Exception::Class
in thread Catching a 'division by zero' error with Exception::Class

The exception even happens before the eval block is entered. This is because perl calculates immediate expressions during compile time.

That's only true for older perls:

$ perl5.10.0 -ce '1/0' -e syntax OK $ perl5.8.8 -ce '1/0' Illegal division by zero at -e line 1.

(I think it was intentionally removed in newer perls because it could break code even if it's not reachable; consider this example:

my $DEBUG = 0; ... if ($DEBUG) { $verbosity = 10 / $DEBUG; }

in which case constant folding might break things).

(Update: in that last example there is no constant folding at all, because variables are not constant folded. ikegami suggested to use constant DEBUG => 0; instead, which should better demonstrate what I was thinking about).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://711488]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-23 11:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found