Add ::Exception, and use throw instead of die.
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Exception.pm
1 package DBIx::Class::Exception;
2
3 use strict;
4 use vars qw[@ISA $DBIC_EXCEPTION_CLASS];
5 use UNIVERSAL::require;
6
7 BEGIN {
8     push( @ISA, $DBIC_EXCEPTION_CLASS || 'DBIx::Class::Exception::Base' );
9 }
10
11 package DBIx::Class::Exception::Base;
12
13 use strict;
14 use Carp ();
15
16 =head1 NAME
17
18 DBIx::Class::Exception - DBIC Exception Class
19
20 =head1 SYNOPSIS
21
22    DBIx::Class::Exception->throw( qq/Fatal exception/ );
23
24 See also L<DBIx::Class>.
25
26 =head1 DESCRIPTION
27
28 This is a generic Exception class for DBIx::Class. You can easily
29 replace 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
42 Throws a fatal exception.
43
44 =cut
45
46 sub throw {
47     my $class  = shift;
48     my %params = @_ == 1 ? ( error => $_[0] ) : @_;
49
50     my $message = $params{message} || $params{error} || $! || '';
51
52     local $Carp::CarpLevel = 1;
53
54     Carp::croak($message);
55 }
56
57 =back
58
59 =head1 AUTHOR
60
61 Marcus Ramberg <mramberg@cpan.org>
62
63 =head1 THANKS
64
65 Thanks to the L<Catalyst> framework, where this module was borrowed
66 from.
67
68 =head1 COPYRIGHT
69
70 This program is free software, you can redistribute it and/or modify
71 it under the same terms as Perl itself.
72
73 =cut
74
75 1;