in reply to Re: Catching a 'division by zero' error with Exception::Class
in thread Catching a 'division by zero' error with Exception::Class
I completely agree, eval-die is flexible enough for most use. Is there any advantage with hierarchical exceptions which is worth the addition code and modules?
The original problem can be written as:
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";
Updated: this code doesn't work properly before Perl 5.10, so I added a 'use' statement to stop it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Catching a 'division by zero' error with Exception::Class
by mr_mischief (Monsignor) on Sep 19, 2008 at 23:26 UTC | |
by ggvaidya (Pilgrim) on Sep 20, 2008 at 09:17 UTC | |
by mr_mischief (Monsignor) on Sep 22, 2008 at 14:23 UTC |