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
22 my $e = $@; # like() seems to stringify $@
25 # Re-throw the exception with rethrow()
27 isa_ok( $@, 'DBIx::Class::Exception' );
30 # Now lets rethrow via exception_action
31 $schema->exception_action(sub { die @_ });
35 # Now lets suppress the error
36 $schema->exception_action(sub { 1 });
38 ok(!$@, "Suppress exception");
40 # Now lets fall through and let croak take back over
41 $schema->exception_action(sub { return });
45 # Whacky useless exception class
47 package DBICTest::Exception;
48 use overload '""' => \&stringify, fallback => 1;
51 bless { msg => shift }, $class;
55 die $self if ref $self eq __PACKAGE__;
56 die $self->new(shift);
59 "DBICTest::Exception is handling this: " . shift->{msg};
63 # Try the exception class
64 $schema->exception_action(sub { DBICTest::Exception->throw(@_) });
66 like($@, qr/DBICTest::Exception is handling this: $ex_regex/);
68 # While we're at it, lets throw a custom exception through Storage::DBI
69 eval { $schema->storage->throw_exception('floob') };
70 like($@, qr/DBICTest::Exception is handling this: floob/);
73 # This usage is a bit unusual but it was actually seen in the wild
76 my $dbh = $schema->storage->dbh;
79 $dbh->do ('glaring_syntax_error;');
81 like($@, qr/DBI Exception.+do failed/, 'Exception thrown even after $storage is destroyed');