10 # Set up the "usual" sqlite for DBICTest
11 my $schema = DBICTest->init_schema;
13 # This is how we're generating exceptions in the rest of these tests,
14 # which might need updating at some future time to be some other
15 # exception-generating statement:
17 sub throwex { $schema->resultset("Artist")->search(1,1,1); }
18 my $ex_regex = qr/Odd number of arguments to search/;
20 # Basic check, normal exception
26 # Re-throw the exception with rethrow()
27 throws_ok { $e->rethrow }
29 isa_ok( $@, 'DBIx::Class::Exception' );
31 # Now lets rethrow via exception_action
32 $schema->exception_action(sub { die @_ });
37 # This should have never worked!!!
39 # Now lets suppress the error
40 $schema->exception_action(sub { 1 });
42 qr/exception_action handler .+ did \*not\* result in an exception.+original error: $ex_regex/;
44 # Now lets fall through and let croak take back over
45 $schema->exception_action(sub { return });
47 warnings_are { throwex }
48 qr/exception_action handler installed .+ returned false instead throwing an exception/;
51 # again to see if no warning
53 warnings_are { throwex }
58 # Whacky useless exception class
60 package DBICTest::Exception;
61 use overload '""' => \&stringify, fallback => 1;
64 bless { msg => shift }, $class;
68 die $self if ref $self eq __PACKAGE__;
69 die $self->new(shift);
72 "DBICTest::Exception is handling this: " . shift->{msg};
76 # Try the exception class
77 $schema->exception_action(sub { DBICTest::Exception->throw(@_) });
79 qr/DBICTest::Exception is handling this: $ex_regex/;
81 # While we're at it, lets throw a custom exception through Storage::DBI
82 throws_ok { $schema->storage->throw_exception('floob') }
83 qr/DBICTest::Exception is handling this: floob/;