Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

throw X::OutOfRange exception from Date and DateTime constructors

  • Loading branch information...
commit 4b4f5efb4a87bd2c0b9fc162f619c7c6b288bb2c 1 parent c838c1c
Moritz Lenz moritz authored

Showing 2 changed files with 13 additions and 1 deletion. Show diff stats Hide diff stats

  1. +8 0 src/core/Exceptions.pm
  2. +5 1 src/core/Temporal.pm
8 src/core/Exceptions.pm
@@ -23,4 +23,12 @@ my package X {
23 23 has $.feature;
24 24 }
25 25
  26 + class OutOfRange is Base {
  27 + has $.what = 'Argument';
  28 + has $.got = '<unknown>';
  29 + has $.range = '<unknown>';
  30 + method message() {
  31 + "$.what out of range. Is: $.got, should be in $.range"
  32 + }
  33 + }
26 34 }
6 src/core/Temporal.pm
@@ -92,7 +92,11 @@ my role Dateish {
92 92 method check-value($val is copy, $name, $range, :$allow-nonint) {
93 93 $val = $allow-nonint ?? +$val !! $val.Int;
94 94 $val ~~ $range
95   - or die "$name must be in {$range.perl}\n";
  95 + or die X::OutOfRange.new(
  96 + what => $name,
  97 + got => $val,
  98 + range => $range.perl,
  99 + );
96 100 }
97 101
98 102 method check-date {

0 comments on commit 4b4f5ef

Please sign in to comment.
Something went wrong with that request. Please try again.