#!/usr/bin/perl -w # # Example of catching errors in perl # print " OK, we're going to do division, namely top/bottom \n"; print " top = ? "; chomp(my $top = <>); print " bottom = ? "; chomp(my $bottom = <>); my $answer; # This part will continue on even if something really bad happens. eval { if ($top < 0) { die " Exception: top is less than zero "; } $answer = $top / $bottom; print " The answer is $answer \n"; }; if ($@) { print " Something bad happened : '$@' \n"; } print " continuing on... \n";