Created
May 3, 2012 16:28
-
-
Save felher/2587005 to your computer and use it in GitHub Desktop.
some thinking about exceptions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/core/Exception.pm b/src/core/Exception.pm | |
index bab8e99..453613b 100644 | |
--- a/src/core/Exception.pm | |
+++ b/src/core/Exception.pm | |
@@ -156,6 +156,9 @@ my role X::OS { | |
} | |
my role X::IO does X::OS { }; | |
+my role X::IO::FileNotFound { | |
+ has $.file-not-found; | |
+} | |
my class X::IO::Rename does X::IO is Exception { | |
has $.from; | |
diff --git a/src/core/IO.pm b/src/core/IO.pm | |
index 869fc7c..525128b 100644 | |
--- a/src/core/IO.pm | |
+++ b/src/core/IO.pm | |
@@ -383,18 +383,26 @@ sub rename(Cool $from as Str, Cool $to as Str) { | |
} | |
} | |
} | |
+ | |
+my role X::IO::FileNotFound { ... } | |
my class X::IO::Copy { ... } | |
sub copy(Cool $from as Str, Cool $to as Str) { | |
pir::new__PS('File').copy(nqp::unbox_s($from), nqp::unbox_s($to)); | |
return True; | |
CATCH { | |
+ my $x = X::IO::Copy.new( | |
+ :$from, | |
+ :$to, | |
+ os-error => .Str, | |
+ ); | |
+ | |
+ when .Str ~~ "No such file or directory" { | |
+ $x does X::IO::FileNotFound(file-not-found => $from); | |
+ $x.throw(); | |
+ } | |
+ | |
default { | |
- X::IO::Copy.new( | |
- :$from, | |
- :$to, | |
- os-error => .Str, | |
- ).throw; | |
+ $x.throw(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment