Skip to content

Commit

Permalink
Add X::Syntax::Number::InvalidCharacter exception
Browse files Browse the repository at this point in the history
The exception is to be used by .parse-base() routine to indicate a
string contains a character that is not a valid character in the base
the number is being converted to.

e.g. of output: "Invalid base-30 character: Perl6⏏ Is Great"

Awesomified with colour support.
  • Loading branch information
zoffixznet committed Nov 14, 2016
1 parent 189cb23 commit 2faa55b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/core/Exception.pm
Expand Up @@ -1491,6 +1491,17 @@ my class X::Syntax::Number::RadixOutOfRange does X::Syntax {
method message() { "Radix $.radix out of range (allowed: 2..36)" }
}

my class X::Syntax::Number::InvalidCharacter does X::Syntax {
has $.radix;
has $.str;
method message() {
my ($R,$C,$G,$Y,$E) = Rakudo::Internals.error-rcgye;
$!pos = 0 if $!pos < 0; # radix_I returns -1 if first char is bad
my ($pre, $post) = .substr(0, $!pos), .substr($!pos) given $!str;
"Invalid base-$!radix character: $G$pre$Y$E$R$post$C";
}
}

my class X::Syntax::Number::IllegalDecimal does X::Syntax {
method message() { "Decimal point must be followed by digit" }
}
Expand Down

0 comments on commit 2faa55b

Please sign in to comment.