From: Brandon L. Black Date: Tue, 19 Jun 2007 00:21:56 +0000 (+0000) Subject: exception rethrow method from LTJake X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b2f408f3651f1f86865e4f850858fe73ad18a084;p=dbsrgits%2FDBIx-Class-Historic.git exception rethrow method from LTJake --- diff --git a/Changes b/Changes index 43a46e9..a6dca8f 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Revision history for DBIx::Class + - new method "rethrow" for our exception objects + 0.08001 2007-06-17 21:21:02 - Cleaned up on_connect handling for versioned - removed DateTime use line from multi_create test diff --git a/lib/DBIx/Class/Exception.pm b/lib/DBIx/Class/Exception.pm index 83e0255..77a3a96 100644 --- a/lib/DBIx/Class/Exception.pm +++ b/lib/DBIx/Class/Exception.pm @@ -68,6 +68,17 @@ sub throw { die $self; } +=head2 rethrow + +This method provides some syntactic sugar in order to +re-throw exceptions. + +=cut + +sub rethrow { + die shift; +} + =head1 AUTHORS Brandon L. Black diff --git a/t/34exception_action.t b/t/34exception_action.t index 7fef551..8fd70ba 100644 --- a/t/34exception_action.t +++ b/t/34exception_action.t @@ -5,7 +5,7 @@ use Test::More; use lib qw(t/lib); use DBICTest; -plan tests => 6; +plan tests => 8; # Set up the "usual" sqlite for DBICTest my $schema = DBICTest->init_schema; @@ -19,6 +19,12 @@ my $ex_regex = qr/Odd number of arguments to search/; # Basic check, normal exception eval { throwex }; +my $e = $@; # like() seems to stringify $@ +like($@, $ex_regex); + +# Re-throw the exception with rethrow() +eval { $e->rethrow }; +isa_ok( $@, 'DBIx::Class::Exception' ); like($@, $ex_regex); # Now lets rethrow via exception_action