Error::TryCatch

OO-ish Exception Handling through source filtering
Download

Error::TryCatch Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Nilson Santos Figueiredo JĂșnior
  • Publisher web site:
  • http://search.cpan.org/~nilsonsfj/

Error::TryCatch Tags


Error::TryCatch Description

OO-ish Exception Handling through source filtering Error::TryCatch is a Perl module that implements exception handling (try-catch) blocks functionality with an interface similiar to Error.pm (in fact, it's almost a drop-in replacement). The main difference is that it's a source filter module.As a source filter it can implement the same convenient interface without those nasty memory leaks and implicit anonymous subroutines (which can trick you, if you're not careful). Also after source parsing it converts the code into "native" perl code, so it's probably a little faster than Error.pm's approach.And, well. As far as I can tell, Error::TryCatch accomplishes its duty nicely.SYNOPSIS use Error::TryCatch; try { dangerous_code(); even_more_dangerous_code(); throw new Error::Generic -text => "well, no one can live in danger forever"; } catch Error::Unhandled with { # normal die()s are translated into Error::Unhandled exceptions print "caught an unhandled perl exception: $@\n"; } catch Error::NewExceptionClass with { # code that handles Error::NewExceptionClass } catch Error::YetAnotherExceptions { # note that 'with' is optional (this differs from Error.pm) } otherwise { # catch any other exception which might not have been caught my $exception_class = ref($@}; print "someone has thrown a $exception_class exception: $@\n"; } finally { clean_up(); # which will always be executed }; # don't forget the trailing ';' otherwise bad things *will* happen Requirements: · Perl


Error::TryCatch Related Software