8 # Set up the "usual" sqlite for DBICTest
9 my $schema = DBICTest->init_schema;
11 # This is how we're generating exceptions in the rest of these tests,
12 # which might need updating at some future time to be some other
13 # exception-generating statement:
15 sub throwex { $schema->resultset("Artist")->search(1,1,1); }
16 my $ex_regex = qr/Odd number of arguments to search/;
18 # Basic check, normal exception
20 my $e = $@; # like() seems to stringify $@
23 # Re-throw the exception with rethrow()
25 isa_ok( $@, 'DBIx::Class::Exception' );
28 # Now lets rethrow via exception_action
29 $schema->exception_action(sub { die @_ });
33 # Now lets suppress the error
34 $schema->exception_action(sub { 1 });
36 ok(!$@, "Suppress exception");
38 # Now lets fall through and let croak take back over
39 $schema->exception_action(sub { return });
43 # Whacky useless exception class
45 package DBICTest::Exception;
46 use overload '""' => \&stringify, fallback => 1;
49 bless { msg => shift }, $class;
53 die $self if ref $self eq __PACKAGE__;
54 die $self->new(shift);
57 "DBICTest::Exception is handling this: " . shift->{msg};
61 # Try the exception class
62 $schema->exception_action(sub { DBICTest::Exception->throw(@_) });
64 like($@, qr/DBICTest::Exception is handling this: $ex_regex/);
66 # While we're at it, lets throw a custom exception through Storage::DBI
67 eval { $schema->storage->throw_exception('floob') };
68 like($@, qr/DBICTest::Exception is handling this: floob/);