Make exception stringify as their message.
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Exception.pm
CommitLineData
a2f2cde9 1package Catalyst::Exception;
2
3cdcf968 3# XXX: See bottom of file for Exception implementation
a2f2cde9 4
5package Catalyst::Exception::Base;
6
3cdcf968 7use Moose;
a80247cf 8use Carp;
9use namespace::clean -except => 'meta';
a2f2cde9 10
11=head1 NAME
12
13Catalyst::Exception - Catalyst Exception Class
14
15=head1 SYNOPSIS
16
17 Catalyst::Exception->throw( qq/Fatal exception/ );
18
19See also L<Catalyst>.
20
21=head1 DESCRIPTION
22
23This is the Catalyst Exception class.
24
25=head1 METHODS
26
b5ecfcf0 27=head2 throw( $message )
a2f2cde9 28
b5ecfcf0 29=head2 throw( message => $message )
ebfde331 30
b5ecfcf0 31=head2 throw( error => $error )
a2f2cde9 32
33Throws a fatal exception.
34
35=cut
36
9ffa230b 37has message => (
38 is => 'ro',
39 isa => 'Str',
40);
41
0af1b40c 42use overload q{""} => \&as_string;
43
44sub as_string {
45 my ($self) = @_;
46 return $self->message;
47}
48
a2f2cde9 49sub throw {
50 my $class = shift;
51 my %params = @_ == 1 ? ( error => $_[0] ) : @_;
52
53 my $message = $params{message} || $params{error} || $! || '';
54
55 local $Carp::CarpLevel = 1;
56
a80247cf 57 croak($message);
a2f2cde9 58}
59
3cdcf968 60=head2 meta
61
62Provided by Moose
63
2f381252 64=head1 AUTHORS
a2f2cde9 65
2f381252 66Catalyst Contributors, see Catalyst.pm
a2f2cde9 67
68=head1 COPYRIGHT
69
536bee89 70This library is free software. You can redistribute it and/or modify
a2f2cde9 71it under the same terms as Perl itself.
72
73=cut
74
e5ecd5bc 75Catalyst::Exception::Base->meta->make_immutable;
76
3cdcf968 77package Catalyst::Exception;
78
79use Moose;
a80247cf 80use namespace::clean -except => 'meta';
81
3cdcf968 82use vars qw[$CATALYST_EXCEPTION_CLASS];
83
84BEGIN {
85 extends($CATALYST_EXCEPTION_CLASS || 'Catalyst::Exception::Base');
86}
87
6680c772 88__PACKAGE__->meta->make_immutable;
e5ecd5bc 89
a2f2cde9 901;