File: example.pl

package info (click to toggle)
liberror-perl 0.17-1.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 196 kB
  • ctags: 63
  • sloc: perl: 1,056; makefile: 38
file content (51 lines) | stat: -rw-r--r-- 719 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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;
}