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: $?") );

Social tagging: >

Comments are closed.