Try::Tiny::SmartCatch

Lightweight Perl module for powerful exceptions handling
Download

Try::Tiny::SmartCatch Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Marcin Sztolcman
  • Publisher web site:
  • http://search.cpan.org/~mysz/

Try::Tiny::SmartCatch Tags


Try::Tiny::SmartCatch Description

Try::Tiny::SmartCatch is a simple Perl module to handle exceptions. It's mostly a copy of Try::Tiny module by Yuval Kogman, but with some additional features I need.Main goal for this changes is to add ability to catch only desired exceptions. Additionally, it uses no more anonymous subroutines - there are public sub's definitions. This gave you less chances to forgot that return statement exits just from exception handler, not surrounding function call.If you want to read about other assumptions, read about our predecessor: Try::Tiny.SYNOPSIS use Try::Tiny::SmartCatch; # call some code and just silence errors: try sub { # some code which my die }; # call some code with expanded error handling (throw exceptions as object) try sub { die (Exception1->new ('some error')); }, catch_when 'Exception1' => sub { # handle Exception1 exception }, catch_when => sub { # handle Exception2 or Exception3 exception }, catch_default sub { # handle all other exceptions }, finally sub { # and finally run some other code }; # call some code with expanded error handling (throw exceptions as strings) try sub { die ('some error1'); }, catch_when 'error1' => sub { # search for 'error1' in message }, catch_when qr/error\d/ => sub { # search exceptions matching message to regexp }, catch_when => sub { # search for 'error2' or match 'error\d in message }, catch_default sub { # handle all other exceptions }, finally sub { # and finally run some other code }; # try some code, and execute the other if it pass try sub { say 'some code'; return 'Hello, world!'; }, catch_default sub { say 'some exception caught: ', $_; }, then sub { say 'all passed, no exceptions found. Message from try block: ' . $_; };Product's homepage


Try::Tiny::SmartCatch Related Software