HTTP::Exception

Throw HTTP-Errors as (Exception::Class-) Exceptions
Download

HTTP::Exception Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Thomas Muller
  • Publisher web site:
  • http://search.cpan.org/~tmueller/

HTTP::Exception Tags


HTTP::Exception Description

Every HTTP::Exception is a Exception::Class - Class. So the same mechanisms apply as with Exception::Class-classes. In fact have a look at Exception::Class' docs for more general information on exceptions and Exception::Class::Base for information on what methods a caught exception also has.HTTP::Exception is only a factory for HTTP::Exception::XXX (where X is a number) subclasses. That means that HTTP::Exception->new(404) returns a HTTP::Exception::404 object, which in turn is a HTTP::Exception::Base - Object.Don't bother checking a caught HTTP::Exception::...-class with "isa" as it might not contain what you would expect. Use the code- or status_message-attributes and the is_ -methods instead.The subclasses are created at compile-time, ie the first time you make "use HTTP::Exception". See paragraph below for the naming scheme of those subclasses.Subclassing the subclasses works as expected.SYNOPSISHTTP::Exception lets you throw HTTP-Errors as Exceptions. use HTTP::Exception; # throw a 404 Exception HTTP::Exception->throw(404); # later in your framework eval { ... }; if (my $e = HTTP::Exception->caught) { # do some errorhandling stuff print $e->code; # 404 print $e->status_message; # Not Found }You can also throw HTTP::Exception-subclasses like this. # same 404 Exception eval { HTTP::Exception::404->throw(); }; eval { HTTP::Exception::NOT_FOUND->throw(); };And catch them accordingly. # same 404 Exception eval { HTTP::Exception::404->throw(); }; if (my $e = HTTP::Exception::405->caught) { do stuff } # won't catch if (my $e = HTTP::Exception::404->caught) { do stuff } # will catch if (my $e = HTTP::Exception::NOT_FOUND->caught) { do stuff } # will catch if (my $e = HTTP::Exception::4XX->caught) { do stuff } # will catch all 4XX Exceptions if (my $e = HTTP::Exception->caught) { do stuff } # will catch every HTTP::Exception if (my $e = Exception::Class->caught) { do stuff } # catch'em allYou can create Exceptions and not throw them, because maybe you want to set some fields manually. See "FIELDS" in HTTP::Exception and "ACCESSORS" in HTTP::Exception for more info. # is not thrown, ie doesn't die, only created my $e = HTTP::Exception->new(404); # usual stuff works $e->code; # 404 $e->status_message # Not Found # set status_message to something else $e->status_message('Nothing Here') # fails, because code is only an accessor, see section ACCESSORS below # $e->code(403); # and finally throw our prepared exception $e->throw;Product's homepage


HTTP::Exception Related Software