blob: 26eb523a3293e620b35d402be35c1dbe5e434e86 (
plain)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#!/usr/bin/perl -w
use strict;
use Test::More tests => 3;
use Error qw(:try);
package MyError::Foo;
use vars qw(@ISA);
@ISA=qw(Error);
package MyError::Bar;
use vars qw(@ISA);
@ISA=qw(Error);
package main;
{
eval
{
try
{
die "Hello";
}
catch MyError::Foo with {
};
};
my $err = $@;
# TEST
ok($err->isa("Error::Simple"), "Error was auto-converted to Error::Simple");
}
sub throw_MyError_Bar
{
my $args = shift;
my $err = MyError::Bar->new();
$err->{'MyBarText'} = $args->{'text'};
return $err;
}
{
local $Error::ObjectifyCallback = \&throw_MyError_Bar;
eval
{
try
{
die "Hello\n";
}
catch MyError::Foo with {
};
};
my $err = $@;
# TEST
ok ($err->isa("MyError::Bar"), "Error was auto-converted to MyError::Bar");
# TEST
is ($err->{'MyBarText'}, "Hello\n", "Text of the error is correct");
}
|