A Perl of an idea for try … catch clauses

The try…catch…finally clause found in languages like Java are very handy for error handling. In scripting languages like Perl you can achieve the same effect using the eval function as the following code snippet demonstrates.


eval{ &yourSubRoutine($parameters); };
$@ ? $yourLogObject->yourErrorMethod("I failed with reason: $@") ):
$yourLogObject->yourTraceMethod("Everything was good: $?") );

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">