1 package DBIx::Class::Exception;
6 use Carp::Clan qw/^DBIx::Class|^Try::Tiny/;
7 use Scalar::Util qw/blessed/;
12 '""' => sub { shift->{msg} },
17 DBIx::Class::Exception - Exception objects for DBIx::Class
21 Exception objects of this class are used internally by
22 the default error handling of L<DBIx::Class::Schema/throw_exception>
23 to prevent confusing and/or redundant re-application of L<Carp>'s
24 stack trace information.
26 These objects stringify to the contained error message, and use
27 overload fallback to give natural boolean/numeric values.
35 =item Arguments: $exception_scalar, $stacktrace
39 This is meant for internal use by L<DBIx::Class>'s C<throw_exception>
40 code, and shouldn't be used directly elsewhere.
42 Expects a scalar exception message. The optional argument
43 C<$stacktrace> tells it to use L<Carp/longmess> instead of
46 DBIx::Class::Exception->throw('Foo');
47 try { ... } catch { DBIx::Class::Exception->throw(shift) }
52 my ($class, $msg, $stacktrace) = @_;
54 # Don't re-encapsulate exception objects of any kind
55 die $msg if blessed($msg);
57 # use Carp::Clan's croak if we're not stack tracing
59 try { croak $msg } catch { $msg = shift };
62 $msg = Carp::longmess($msg);
65 my $self = { msg => $msg };
66 bless $self => $class;
73 This method provides some syntactic sugar in order to
84 Brandon L. Black <blblack@gmail.com>
88 You may distribute this code under the same terms as Perl itself.