#!/usr/local/bin/perl
use strict;
use warnings 'all';
use vars qw(%catchable);
%catchable = ();
sub throw {
print "in $_[0], deciding if i should throw $_[1]: " .
(exists $catchable{$_[1]} ? "sure\n" : "nope, won't be caught\
+n");
}
sub foo {
# try { bar(); baz() } catch foo { ... }
local %catchable = %catchable;
$catchable{'foo'} = 1;
bar();
baz();
}
sub bar {
# try { yak(); } catch bar-1 { ... } catch bar-2 { ... }
local %catchable = %catchable;
$catchable{'bar-1'} = $catchable{'bar-2'} = 1;
yak();
}
sub baz {
# do some stufff...
throw('baz','foo');
throw('baz','uncaught-exception-1');
}
sub yak {
throw('yak','foo');
throw('yak','bar-1');
throw('yak','bar-2');
throw('yak','uncaught-exception-2');
}
foo();
__DATA__
bester:~> tmp/monk.pl
in yak, deciding if i should throw foo: sure
in yak, deciding if i should throw bar-1: sure
in yak, deciding if i should throw bar-2: sure
in yak, deciding if i should throw uncaught-exception-2: nope, won't b
+e caught
in baz, deciding if i should throw foo: sure
in baz, deciding if i should throw uncaught-exception-1: nope, won't b
+e caught
|