Pm Error
Contents |
Dependencies Annotate this POD CPAN RT Open 0 View/Report Bugs Module Version: 0.07 Source NAME SYNOPSIS DESCRIPTION FUNCTIONS EXCEPTION CLASSES CAVEATS BUGS SEE ALSO AUTHOR COPYRIGHT & LICENSE NAME Error::TryCatch - OO-ish Exception Handling through source perl throw filtering SYNOPSIS use Error::TryCatch; try { dangerous_code(); even_more_dangerous_code(); throw new Error::Generic -text =>
Perl Error Rpm
"well, no one can live in danger forever"; } catch Error::Unhandled with { # normal die()s are translated into Error::Unhandled perl error handling 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) } perl exception handling 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 DESCRIPTION Error::TryCatch implements exception handling (try-catch) blocks functionality with an interface similiar to Error.pm (in fact, it's almost a drop-in
Perl Try
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. FUNCTIONS The interface is pretty straight-forward. I think that reading the synopsis is enough documentation. If you *really* need an explanation about how exception handling blocks work, you should take a look at Error.pm documentation. The only clause which I chose not to implement was the 'except' clause, since I consider it rather "exotic" and pretty much useless (at least for my purposes). And it would be a pain to implement. Unlike Error.pm, with Error::TryCatch you can return() from anywhere, but see CAVEATS below. EXCEPTION CLASSES Error::TryCatch was built with exception classes in mind and will even wrap anything it catches that is not a reference into a default unhandled exception class, which defaults to Error::Unhandled (which inherits from Error::Generic). If you want to use a
exceptions of a certain class http://search.cpan.org/~nilsonsfj/Error-TryCatch-0.07/lib/Error/TryCatch.pm explicitly, and differentiate between several types of exceptions. Error.pm provides a lot of syntactic sugar that tends to break easily. As http://www.shlomifish.org/lecture/Perl/Newbies/lecture4/exceptions/error.pm.html such, its use is not too recommended. On the other side, there's the Exception-Class module which provides object-oriented exceptions with no special syntactic sugar, and which works very well. Its use is highly recommended. Throwing objects which are associated with classes is a good way to be able to handle one's exceptions programatically . Contents Up Prev Next Written by Shlomi Fish
Sign in Pricing Blog Support Search GitHub This repository Watch 1 Star 1 Fork 0 ingydotnet/error-errors-pm Code Issues 2 Pull requests 0 Projects 0 Pulse Graphs Error Handling for Perl 26 commits 1 branch 10 releases Fetching contributors Perl https://github.com/ingydotnet/error-errors-pm 100.0% Perl Clone or download Clone with HTTPS Use Git or checkout with SVN using the web URL. Open in Desktop Download ZIP Find file Branch: master Switch branches/tags Branches Tags master Nothing to show 0.13 0.12 0.11 0.10 0.09 0.08 0.07 0.06 0.05 0.04 Nothing to show New pull request Fetching latest commit… Cannot retrieve the latest commit at this time. Permalink Failed to load latest commit information. doc lib test .travis.yml Changes Contributing perl error Makefile Meta ReadMe.pod ReadMe.pod NAME errors - Error Handling for Perl STATUS this module is still under design. Don't use it in production yet. See errors::Design for more information. A few things in this documentation are not yet implemented. NOTE: If you have suggestions as to how this module should behave, now is a great time to contact the author. SYNOPSIS use strict; use warnings; use errors; use errors -class => 'UncoolError'; try { $cool perl error rpm = something(); throw UncoolError("Something is not cool") if not $cool; assert($ok, "Everything is ok"); } catch UncoolError with { my $e = shift; warn "$e"; } catch UserError, RuntimeError with { # catch UserError or RuntimeError # $_ is the same as $_[0] warn; } except { # $@ is the same as $_[0] warn "Some other error: $@"; } otherwise { warn "No error occurred in the try clause." } finally { cleanup(); }; DESCRIPTION The errors module adds clean, simple, sane, flexible and usable error handling to Perl. The module does several things: First, errors exports an error handling syntax that is very similar to Error.pm, but with a few improvements. (See [COMPARISON TO Error.pm]) Second, all errors that are thrown are first class Perl objects. They all inherit from the Exception class, which is provided by default. This allows you to manipulate errors in a consistent and intuitive way. Third, The errors module makes it trivial to define your own error classes, and encourages you to do so. Simply define a class that inherits from Exception (or one of its subclasses). Fourth, errors turns plain (string based) system errors and other die/croak errors into specific Perl objects. It uses heuristics on the error string to determine which Error class to use, and defaults to the RuntimeError class. Fifth, errors prov