eBay::Exception

eBay::Exception is an eBay exception handling framework.
Download

eBay::Exception Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Jeff Nokes
  • Publisher web site:
  • http://search.cpan.org/~ebay/eBay-API-0.22/lib/eBay/API/XML/BaseDataType.pm

eBay::Exception Tags


eBay::Exception Description

eBay::Exception is an eBay exception handling framework. eBay::Exception is an eBay exception handling framework.SYNOPSIS use eBay::API::XML::Session; use eBay::Exception qw(:try); # Uncomment this line to enable the catch block below # eBay::Exception::enableExceptions(); try { # Example of bad argument to Session constructor my $apisession = eBay::API::XML::Session->new('yo'); } catch Error with { my $error = shift; print $error->{argnumber}; # specific to usage errors print $error->{package}; # package where error trapped print $error->{trace}; # stack trace print $error; # exception type print "nnCATCHING THE EXCEPTON!n"; } finally { #optional cleanup code; print "nIN FINALLY BLOCK.n"; }; # Don't forget the semicolon, this is not a block, but a statement!EXTENDING EXCEPTION HANDLINGIt is simple to extend the framework to use it in your own application code. You can define exception classes that inherit from any pre-existing Extension::Class and then use and throw these classes in your own application code. If you extend from an eBay exception class, then any exceptions you throw will also be logged to the eBay logging facility if you throw the exception with the instance method ebay_throw(). Whether the exception will actually be thrown, of course, depends on whether you have enabled exceptions. If you just throw() the exception, it will always be thrown, and there will be no message to the eBay API logging.Example: package myException; use eBay::Exception; use base qw(eBay::Exception); sub foo { print "I AM IN FOO.n"; } 1; package main; use eBay::Exception qw(:try); # Comment out following to disable the catch block eBay::Exception::enableExceptions(); try { myNewThrow(); } catch Error with { print "CATCHING myNewThrow().n"; my $error = shift; if ($error->isa('myException') ) { print "myException ERROR: " . $error->error . "n"; $error->foo(); } } finally { #optional cleanup code; print "I AM CLEANING UP.n"; }; sub myNewThrow { # log and (maybe) actually throw myException->ebay_throw( error => "This is a foo error." ); # or just throw and always throw regardless # myException->throw( error => "This is a foo error." ); } 1;enableExceptions()When called tells the exception framework to throw exceptions. This has the effect of activating any exception handling logic in catch portion of a try/catch statement.disableExceptions()This reverses the effect of calling enableExceptions(). The default for the exception handling framework is for it to be disabled.ebay_throw()Extract information from the exception being thrown, including a stack trace, and log this information with the API logging framework. If exceptions are enabled, then call Exception::Class::throw() to throw the exception. This will cause the exception handling logic in the catch portion of the try/catch statement to execute. Requirements: · Perl


eBay::Exception Related Software