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