A Perl of an idea for try … catch clauses

3 January, 2007 – 10:20 am

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

Share it: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Netscape
  • Reddit
  • Slashdot
  • Technorati
  • YahooMyWeb

Post a Comment

*
To prove that you're not a bot, enter this code
Anti-Spam Image