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 my $throw = sub { $schema->resultset("Artist")->search(1,1,1) };
18 my $ex_regex = qr/Odd number of arguments to search/;
20 # Basic check, normal exception
21 throws_ok \&$throw, $ex_regex;
25 # Re-throw the exception with rethrow()
26 throws_ok { $e->rethrow }
28 isa_ok( $@, 'DBIx::Class::Exception' );
30 # Now lets rethrow via exception_action
31 $schema->exception_action(sub { die @_ });
32 throws_ok \&$throw, $ex_regex;
35 # This should have never worked!!!
37 # Now lets suppress the error
38 $schema->exception_action(sub { 1 });
40 qr/exception_action handler .+ did \*not\* result in an exception.+original error: $ex_regex/;
42 # Now lets fall through and let croak take back over
43 $schema->exception_action(sub { return });
45 warnings_are \&$throw,
46 qr/exception_action handler installed .+ returned false instead throwing an exception/;
49 # again to see if no warning
51 warnings_are \&$throw,
56 # Whacky useless exception class
58 package DBICTest::Exception;
59 use overload '""' => \&stringify, fallback => 1;
62 bless { msg => shift }, $class;
66 die $self if ref $self eq __PACKAGE__;
67 die $self->new(shift);
70 "DBICTest::Exception is handling this: " . shift->{msg};
74 # Try the exception class
75 $schema->exception_action(sub { DBICTest::Exception->throw(@_) });
77 qr/DBICTest::Exception is handling this: $ex_regex/;
79 # While we're at it, lets throw a custom exception through Storage::DBI
80 throws_ok { $schema->storage->throw_exception('floob') }
81 qr/DBICTest::Exception is handling this: floob/;