Skip to content

Instantly share code, notes, and snippets.

@xaicron
Created July 21, 2011 07:25
Show Gist options
  • Save xaicron/1096726 to your computer and use it in GitHub Desktop.
Save xaicron/1096726 to your computer and use it in GitHub Desktop.
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