Permalink
Browse files

throw X::OutOfRange exception from Date and DateTime constructors

  • Loading branch information...
1 parent c838c1c commit 4b4f5efb4a87bd2c0b9fc162f619c7c6b288bb2c @moritz moritz committed Nov 3, 2011
Showing with 13 additions and 1 deletion.
  1. +8 −0 src/core/Exceptions.pm
  2. +5 −1 src/core/Temporal.pm
@@ -23,4 +23,12 @@ my package X {
has $.feature;
}
+ class OutOfRange is Base {
+ has $.what = 'Argument';
+ has $.got = '<unknown>';
+ has $.range = '<unknown>';
+ method message() {
+ "$.what out of range. Is: $.got, should be in $.range"
+ }
+ }
}
@@ -92,7 +92,11 @@ my role Dateish {
method check-value($val is copy, $name, $range, :$allow-nonint) {
$val = $allow-nonint ?? +$val !! $val.Int;
$val ~~ $range
- or die "$name must be in {$range.perl}\n";
+ or die X::OutOfRange.new(
+ what => $name,
+ got => $val,
+ range => $range.perl,
+ );
}
method check-date {

0 comments on commit 4b4f5ef

Please sign in to comment.