merge resultset branch through revision 371
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Exception.pm
CommitLineData
78bab9ca 1package DBIx::Class::Exception;
2
3use strict;
4use vars qw[@ISA $DBIC_EXCEPTION_CLASS];
5use UNIVERSAL::require;
6
7BEGIN {
8 push( @ISA, $DBIC_EXCEPTION_CLASS || 'DBIx::Class::Exception::Base' );
9}
10
11package DBIx::Class::Exception::Base;
12
13use strict;
14use Carp ();
15
16=head1 NAME
17
18DBIx::Class::Exception - DBIC Exception Class
19
20=head1 SYNOPSIS
21
22 DBIx::Class::Exception->throw( qq/Fatal exception/ );
23
24See also L<DBIx::Class>.
25
26=head1 DESCRIPTION
27
28This is a generic Exception class for DBIx::Class. You can easily
29replace this with any mechanism implementing 'throw' by setting
30$DBix::Class::Exception::DBIC_EXCEPTION_CLASS
31
32=head1 METHODS
33
34=over 4
35
36=item throw( $message )
37
38=item throw( message => $message )
39
40=item throw( error => $error )
41
42Throws a fatal exception.
43
44=cut
45
46sub throw {
47 my $class = shift;
48 my %params = @_ == 1 ? ( error => $_[0] ) : @_;
49
50 my $message = $params{message} || $params{error} || $! || '';
51
07037f89 52 local $Carp::CarpLevel = (caller(1) eq 'NEXT' ? 2 : 1);
78bab9ca 53
54 Carp::croak($message);
55}
56
57=back
58
59=head1 AUTHOR
60
61Marcus Ramberg <mramberg@cpan.org>
62
63=head1 THANKS
64
65Thanks to the L<Catalyst> framework, where this module was borrowed
66from.
67
68=head1 COPYRIGHT
69
70This program is free software, you can redistribute it and/or modify
71it under the same terms as Perl itself.
72
73=cut
74
751;