Skip to content

Commit

Permalink
throws exception instaed of dying
Browse files Browse the repository at this point in the history
  • Loading branch information
sergot committed Jul 17, 2014
1 parent 6a1bb99 commit ad70cee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 10 additions & 1 deletion lib/Encode.pm6
Expand Up @@ -2,6 +2,14 @@ module Encode;

use Encode::Latin2;

my class X::Encode::Unknown is Exception {
has $.encoding;

method message {
"Unknown encoding $.encoding."
}
}

my %encodings =
'iso-8859-2' => &latin2,
'iso_8859-2' => &latin2,
Expand All @@ -10,7 +18,8 @@ my %encodings =
;

our sub decode($encoding, buf8 $buf) {
die "$encoding NIY" unless %encodings{$encoding}.defined;
X::Encode::Unknown.new(:encoding($encoding)).throw unless %encodings{$encoding}.defined;

&(%encodings{$encoding})($buf);
}

Expand Down
3 changes: 1 addition & 2 deletions t/01-basic.t
Expand Up @@ -5,5 +5,4 @@ use Test;

plan 1;

Encode::decode("niy-encoding", buf8.new(97));
dies_ok { Encode::decode("niy-encoding", buf8.new(97)) }, 'dies if NIY';
throws_like 'Encode::decode("nyi-encoding", buf8.new(97))', X::Encode::Unknown, message => 'Unknown encoding nyi-encoding.';

0 comments on commit ad70cee

Please sign in to comment.