diff options
Diffstat (limited to 'examples/example.pl')
-rw-r--r-- | examples/example.pl | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/examples/example.pl b/examples/example.pl new file mode 100644 index 0000000..59da597 --- /dev/null +++ b/examples/example.pl @@ -0,0 +1,51 @@ + +use lib '.'; +use Error qw(:try); + +@Error::Bad::ISA = qw(Error); + +$Error::Debug = 1; # turn on verbose stacktrace + +sub abc { + try { + try { + throw Error::Simple("a simple error"); + } + catch Error::Simple with { + my $err = shift; + throw Error::Bad(-text => "some text"); + } + except { + return { + Error::Simple => sub { warn "simple" } + } + } + otherwise { + 1; + } finally { + warn "finally\n"; + }; + } + catch Error::Bad with { + 1; + }; +} + +sub def { + unlink("not such file") or + record Error::Simple("unlink: $!", $!) and return; + 1; +} + +abc(); + + +$x = prior Error; + +print "--\n",$x->stacktrace; + +unless(defined def()) { + $x = prior Error 'main'; + print "--\n",0+$x,"\n",$x; +} + |