Skip to content

Instantly share code, notes, and snippets.

@leedo
Created January 26, 2013 22:20
Show Gist options
  • Save leedo/4645022 to your computer and use it in GitHub Desktop.
Save leedo/4645022 to your computer and use it in GitHub Desktop.
Any way to catch errors like this?
use AnyEvent;
sub app {
my $hook = shift;
my $cv = AE::cv;
# how to catch any unhandled errors in hook?
$hook->(sub { $cv->send(@_) });
$cv->recv;
}
sub user_hook {
my $callback = shift;
# user defined hook, could include timers,
# AE::http requests, etc
my $t; $t = AE::timer 1, 0, sub {
undef $t;
# some typo causes error
die "something went wrong";
# dies before calling callback
$callback->("no errors");
};
}
app(\&user_hook);
print "done!\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment