<html><head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head><body bgcolor="#FFFFFF" text="#000000">And that's the point. The
throw does not happen. An error is logged, but execution continues as
though there was no error.<br>
<span>
</span><br>
John<br>
<blockquote style="border: 0px none;"
cite="mid:E62965A2-ACCB-4ED3-B680-26CA163202DF@gmail.com" type="cite">
<div style="margin:30px 25px 10px 25px;" class="__pbConvHr"><div
style="width:100%;border-top:2px solid #EDF1F4;padding-top:10px;"> <div
style="display:inline-block;white-space:nowrap;vertical-align:middle;width:49%;">
        <a moz-do-not-send="true" href="mailto:howard.lovatt@gmail.com"
style="color:#485664
!important;padding-right:6px;font-weight:500;text-decoration:none
!important;">Howard Lovatt</a></div> <div
style="display:inline-block;white-space:nowrap;vertical-align:middle;width:48%;text-align:
right;"> <font color="#909AA4"><span style="padding-left:6px">12
November 2017 at 07:43</span></font></div> </div></div>
<div style="color:#909AA4;margin-left:24px;margin-right:24px;"
__pbrmquotes="true" class="__pbConvBody"><div>I don’t have any inside
knowledge on this, i.e. I am not certain I am correct, but my
understanding was that you were meant to let it throw and catch the
error rather than test before hand. <br><br>-- Howard.<br><br></div></div>
<div style="margin:30px 25px 10px 25px;" class="__pbConvHr"><div
style="width:100%;border-top:2px solid #EDF1F4;padding-top:10px;"> <div
style="display:inline-block;white-space:nowrap;vertical-align:middle;width:49%;">
        <a moz-do-not-send="true" href="mailto:marc@snafu.org"
style="color:#485664
!important;padding-right:6px;font-weight:500;text-decoration:none
!important;">Marco S Hyman</a></div> <div
style="display:inline-block;white-space:nowrap;vertical-align:middle;width:48%;text-align:
right;"> <font color="#909AA4"><span style="padding-left:6px">11
November 2017 at 11:51</span></font></div> </div></div>
<div style="color:#909AA4;margin-left:24px;margin-right:24px;"
__pbrmquotes="true" class="__pbConvBody"><div><!----><br>Known (by
Apple) bug. My report was closed as a duplicate of 30350792.<br><br>My
workaround is to do this in my do block after attempting to copy a file
to saveFileUrl:<br><br> try fileManager.copyItem(at: url, to:
saveFileUrl)<br> /// DANGER WILL ROBINSON -- the above call can fail
to return an<br> /// error when the file is not copied. radar filed
and<br> /// closed as a DUPLICATE OF 30350792 which is still open.<br>
/// As a result I must verify that the copied file exists<br> if
!fileManager.fileExists(atPath: (saveFileUrl.path)) {<br>
unexpected(error: nil,<br> "Cannot copy \(url.path) to
\(saveFileUrl.path)")<br> return false<br> }<br><br>which
duplicates what the catch block would do.<br><br>Marc</div></div>
<div style="margin:30px 25px 10px 25px;" class="__pbConvHr"><div
style="width:100%;border-top:2px solid #EDF1F4;padding-top:10px;"> <div
style="display:inline-block;white-space:nowrap;vertical-align:middle;width:49%;">
        <a moz-do-not-send="true" href="mailto:john_brownie@sil.org"
style="color:#485664
!important;padding-right:6px;font-weight:500;text-decoration:none
!important;">John Brownie</a></div> <div
style="display:inline-block;white-space:nowrap;vertical-align:middle;width:48%;text-align:
right;"> <font color="#909AA4"><span style="padding-left:6px">11
November 2017 at 11:31</span></font></div> </div></div>
<div style="color:#909AA4;margin-left:24px;margin-right:24px;"
__pbrmquotes="true" class="__pbConvBody">I have code as follows:
<br>
<br>let fileManager = FileManager.default
<br>do {
<br> try fileManager.createDirectory(at:
destination.deletingLastPathComponent(), withIntermediateDirectories:
true, attributes: nil)
<br> try fileManager.copyItem(at: source, to: destination)
<br> handler(true, nil)
<br>}
<br>catch let theError as NSError {
<br> if theError.code == NSFileWriteNoPermissionError {
<br> ...
<br> }
<br> else {
<br> ...
<br> }
<br>}
<br>catch {
<br> handler(false, NSError(...))
<br>}
<br>
<br>Running on macOS 10.12.6, Xcode 8.3.2, I get to the copyItem call,
which
shows an error on the console:
<br>
<br>2017-11-11 11:18:25.931446+1000 MyApp[32662:2408351] open on
/path/to/file: Permission denied
<br>
<br>But it doesn't go to either of my catch blocks, but goes to the
following line, where the completion handler is to be run. What is going
on?
<br>
<br>John
<br></div>
</blockquote>
<br>
<div class="moz-signature">-- <br>John Brownie<br>
SIL-PNG, Ukarumpa, Eastern Highlands, Papua New Guinea<br>
Mussau-Emira language, New Ireland Province, Papua New Guinea<br>
</div>
</body></html>