| AnyEvent-CouchDB documentation | Contained in the AnyEvent-CouchDB distribution. |
AnyEvent::CouchDB::Exceptions - Exception::Class-based exceptions for AnyEvent::CouchDB
use feature 'switch';
use Try::Tiny;
use Data::Dump 'pp';
use AnyEvent::CouchDB;
my $db = couchdb("food");
try {
my $vegetables = $db->open_doc('vegetables')->recv;
}
catch {
when (ref eq 'AnyEvent::CouchDB::Exception::HTTPError') {
# handle an HTTP error
}
when (ref eq 'AnyEvent::CouchDB::Exception::JSONError') {
# handle a JSON decoding error
}
default {
$_->show_trace(1);
warn "$_";
warn "HEADERS : " . pp($_->headers);
warn "BODY : " . $_->body;
}
};
This module defines a family of exception classes.
The base exception class who's superclass is Exception::Class::Base
A subclass of AnyEvent::CouchDB::Exception for HTTP errors
A subclass of AnyEvent::CouchDB::Exception for JSON decoding errors
This module provides the following methods in addition to the methods provided by Exception::Class::Base.
This method will return the HTTP response headers if they were available at the time the exception was thrown.
This method will return the HTTP response body if it was available at the time the exception was thrown.
| AnyEvent-CouchDB documentation | Contained in the AnyEvent-CouchDB distribution. |
package AnyEvent::CouchDB::Exceptions; use Exception::Class ( 'AnyEvent::CouchDB::Exception' => { fields => [ 'headers', 'body' ], }, 'AnyEvent::CouchDB::Exception::JSONError' => { isa => 'AnyEvent::CouchDB::Exception', description => 'JSON decoding error', }, 'AnyEvent::CouchDB::Exception::HTTPError' => { isa => 'AnyEvent::CouchDB::Exception', description => 'HTTP error', }, ); AnyEvent::CouchDB::Exception->Trace($ENV{ANYEVENT_COUCHDB_DEBUG}); 1; __END__