or test the value before doing the division manually:#!/usr/bin/env perl use Exception::Class; # try eval { (my $result = (23/0)); }; # catch if ( my $e = Exception::Class->caught() ) { # You can rethrow the exception with your own like MyException her +e die "ERROR: division by zero\n$e\n" }
Hope this help.#!/usr/bin/env perl use strict; use Exception::Class ( 'MyException' ); my $number1 = 12; my $number2 = 0; my $result; # try eval { if ($number2 == 0) { MyException->throw( error => 'I feel funny.' ); } $result = $number1 / $number2; }; # catch if ( my $e = Exception::Class->caught('MyException') ) { warn $e->error, "\n", $e->trace->as_string, "\n"; warn join ' ', $e->euid, $e->egid, $e->uid, $e->gid, $e->pid, $e->time; exit; } else { $e = Exception::Class->caught(); ref $e ? $e->rethrow : die $e; }
In reply to Re^3: Catching a 'division by zero' error with Exception::Class
by dwindura
in thread Catching a 'division by zero' error with Exception::Class
by baurel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |