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
24 # Now lets rethrow via exception_action
25 $schema->exception_action(sub { die @_ });
29 # Now lets suppress the error
30 $schema->exception_action(sub { 1 });
32 ok(!$@, "Suppress exception");
34 # Now lets fall through and let croak take back over
35 $schema->exception_action(sub { return });
39 # Whacky useless exception class
41 package DBICTest::Exception;
42 use overload '""' => \&stringify, fallback => 1;
45 bless { msg => shift }, $class;
49 die $self if ref $self eq __PACKAGE__;
50 die $self->new(shift);
53 "DBICTest::Exception is handling this: " . shift->{msg};
57 # Try the exception class
58 $schema->exception_action(sub { DBICTest::Exception->throw(@_) });
60 like($@, qr/DBICTest::Exception is handling this: $ex_regex/);
62 # While we're at it, lets throw a custom exception through Storage::DBI
63 eval { $schema->storage->throw_exception('floob') };
64 like($@, qr/DBICTest::Exception is handling this: floob/);