http://www.perlmonks.org?node_id=712712


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

Thanks for pointing that out! I've put a "use 5.10" line in so it won't run unchanged on pre-5.10 perls. Do you think that's good enough?
  • Comment on Re^4: Catching a 'division by zero' error with Exception::Class

Replies are listed 'Best First'.
Re^5: Catching a 'division by zero' error with Exception::Class
by mr_mischief (Monsignor) on Sep 22, 2008 at 14:23 UTC
    It still exits the shell under which perl is running if it's pasted into 5.8.8's standard input.

    This version still issues commands to the shell but one of them isn't an exit:

    use warnings; use strict; use 5.0100; eval { print 10/0; # equivalent to: die "Illegal division by zero"; }; if($@) { if($@ =~ /Illegal division by zero/) { print "I feel funny\n"; exit; } else { die $@; } } # No exception thrown. print "What do you know, Perl can divide by zero.\n";

    When the code is placed in a file, a proper insufficient version abend happens.

    I'm not sure why exactly this is, but it is obviously some sort of issue with use version; not being processed as one might expect when the code source is standard input. I'm not sure in general how important that is to have fixed, since it is kind of a degenerate case. It'd be useful for example snippets, though, if pasting into the standard input stream worked the same way as writing to a file and calling perl with that file as an argument.