- Fixes for rt.cpan #17322 and #17331
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Exception.pm
1 package Catalyst::Exception;
2
3 use strict;
4 use vars qw[@ISA $CATALYST_EXCEPTION_CLASS];
5 use UNIVERSAL::require;
6
7 BEGIN {
8     push( @ISA, $CATALYST_EXCEPTION_CLASS || 'Catalyst::Exception::Base' );
9 }
10
11 package Catalyst::Exception::Base;
12
13 use strict;
14 use Carp ();
15
16 =head1 NAME
17
18 Catalyst::Exception - Catalyst Exception Class
19
20 =head1 SYNOPSIS
21
22    Catalyst::Exception->throw( qq/Fatal exception/ );
23
24 See also L<Catalyst>.
25
26 =head1 DESCRIPTION
27
28 This is the Catalyst Exception class.
29
30 =head1 METHODS
31
32 =head2 throw( $message )
33
34 =head2 throw( message => $message )
35
36 =head2 throw( error => $error )
37
38 Throws a fatal exception.
39
40 =cut
41
42 sub throw {
43     my $class  = shift;
44     my %params = @_ == 1 ? ( error => $_[0] ) : @_;
45
46     my $message = $params{message} || $params{error} || $! || '';
47
48     local $Carp::CarpLevel = 1;
49
50     Carp::croak($message);
51 }
52
53 =head1 AUTHOR
54
55 Sebastian Riedel, C<sri@cpan.org>
56 Christian Hansen, C<ch@ngmedia.com>
57
58 =head1 COPYRIGHT
59
60 This program is free software, you can redistribute it and/or modify
61 it under the same terms as Perl itself.
62
63 =cut
64
65 1;