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
So if I run this I come to the conclusion, that there is nothing wrong with the handling code. Dependent on which of this two subroutines you run, the flow takes an other conditional.#!/usr/bin/env perl use Exception::Class ( 'MyException' ); sub divbyz { my $z = 0; eval { my $result = ( 23 / $z ) } or MyException->throw( error => 'I feel funny.' ); } sub writeit { eval { open my $FH, ">unwritable_file" } or MyException->throw( error => 'I feel bad.' ); } or MyException->throw( error => 'I feel bad.' ); # try eval { #divbyz(); writeit(); }; # my $e; # catch if ( my $e = Exception::Class->caught('MyException') ) { warn $e->error, "\n", $e->trace->as_string, "\n"; exit; } else { print "finally \n"; $e = Exception::Class->caught(); ref $e ? $e->rethrow : die $e; }
divbyz(); writeit();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Catching a 'division by zero' error with Exception::Class
by dreadpiratepeter (Priest) on Sep 15, 2008 at 16:56 UTC | |
by baurel (Sexton) on Sep 15, 2008 at 18:09 UTC |