1use strict; 2use warnings; 3 4use Test::More; 5 6use Exception::Class ( 7 'Foo', 8 'Bar' => { isa => 'Foo' }, 9); 10 11## no critic (ErrorHandling::RequireCheckingReturnValueOfEval) 12{ 13 eval { Foo->throw( error => 'foo' ) }; 14 15 my $e = Exception::Class->caught('Bar'); 16 17 ok( !$e, 'caught returns false for wrong class' ); 18} 19 20{ 21 eval { Foo->throw( error => 'foo' ) }; 22 23 my $e = Bar->caught(); 24 25 ok( !$e, 'caught returns false for wrong class' ); 26} 27 28{ 29 eval { Foo->throw( error => 'foo' ) }; 30 31 my $e = Exception::Class->caught('Foo'); 32 33 ok( $e, 'caught returns exception for correct class' ); 34 isa_ok( $e, 'Foo' ); 35 is( $e->message, 'foo', 'message is "foo"' ); 36} 37 38{ 39 eval { Foo->throw( error => 'foo' ) }; 40 41 my $e = Foo->caught(); 42 43 ok( $e, 'Foo->caught() returns exception' ); 44 isa_ok( $e, 'Foo' ); 45} 46 47{ 48 eval { Foo->throw( error => 'foo' ) }; 49 50 my $e = Exception::Class->caught(); 51 52 ok( $e, 'Foo->caught() returns exception' ); 53 isa_ok( $e, 'Foo' ); 54} 55 56done_testing(); 57