Created
January 26, 2013 22:20
-
-
Save leedo/4645022 to your computer and use it in GitHub Desktop.
Any way to catch errors like this?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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