Created
July 21, 2011 07:25
-
-
Save xaicron/1096726 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package S::Exception; | |
use strict; | |
use warnings; | |
use parent qw(Class::Accessor::Fast); | |
use overload (q|""| => \&to_string); | |
use Carp qw(croak); | |
our $VERSION = '0.01'; | |
__PACKAGE__->mk_accessors(qw/message code/); | |
sub new { | |
my ($class, %args) = @_; | |
$class->SUPER::new(\%args); | |
} | |
sub throw { | |
my ($class, %args) = @_; | |
croak $class->new(%args); | |
} | |
sub rethrow { | |
my $self = shift; | |
croak $self; | |
} | |
sub to_string { | |
sprintf('%d: %s', $_[0]->{code}, $_[0]->{message} || ''); | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment