Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Sep 022010

Simple try catch block in Perl


Perl don't have try/catch statement by default, but you can simulate using the following way:

eval {
    print 1/0;

if ($@) {
    print "Error message: $@";

When executed, it shows:

Error message: Illegal division by zero at line 7.

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>