Chouette
view release on metacpan or search on metacpan
differently. Another alternative used by some libraries is to accept 2
callbacks, one of which is called in the success case, and the other in
the failure case.
But with both of these methods, what should the callback do when it is
notified of an error? It can't just "die" because nothing will catch the
exception. With the EV event loop you will see this:
EV: error in callback (ignoring): failure: ERROR: relation "no_such_table" does not exist
Even if you wrap an "eval" or a Try::Tiny "try {} catch {}" around the
code the same thing happens. The try/catch is in effect while installing
the callback, but not when the callback is called.
As a consequence of all this, asynchronous web frameworks usually cannot
indicate errors with exceptions. Instead, they require you to respond to
the client from inside the callback:
$dbh->exec("SELECT * FROM no_such_table", sub {
my ($dbh, $rows, $rv) = @_;
lib/Chouette.pm view on Meta::CPAN
# failure. error message is in $@
}
});
Even if C<exec> failed, the callback still gets called. Whether or not it succeeded is indicated by its parameters. You can think of this as a sort of "in-band" signalling. The fact that there was an error, and what exactly that error was, needs to b...
But with both of these methods, what should the callback do when it is notified of an error? It can't just C<die> because nothing will catch the exception. With the L<EV> event loop you will see this:
EV: error in callback (ignoring): failure: ERROR: relation "no_such_table" does not exist
Even if you wrap an C<eval> or a L<Try::Tiny> C<try {} catch {}> around the code the same thing happens. The try/catch is in effect while installing the callback, but not when the callback is called.
As a consequence of all this, asynchronous web frameworks usually cannot indicate errors with exceptions. Instead, they require you to respond to the client from inside the callback:
$dbh->exec("SELECT * FROM no_such_table", sub {
my ($dbh, $rows, $rv) = @_;
if (!$#_) {
$context->respond_500_error("DB error: $@");
return;
}
( run in 0.655 second using v1.01-cache-2.11-cpan-05444aca049 )