macOS: File::findChildFiles makes the debugger stop on swift_willThrow exceptions

This is no real bug but a rather annyoing thing happening lately in debugging sessions. On macOS File::findChildFiles calls some Obj-C foundation framework functions that appear to have been rewritten to Swift under the hood by Apple on more recent macOS versions. The Obj-C interfaces therfore internally call into Swift implementations. While this is all completely transparent to the user, this becomes obvious when debugging with exception breakpoints enabled.

I had a chat with Claude about it since Swift is not my area of expertise, but the conclusion it draws sounds plausible to me:

  1. Swift throws is not an exception. This is the key point. A Swift throw is not C++/ObjC exception machinery: there is no stack unwinding, no landing pads, no __cxa_throw, no personality routine. The error is returned in a reserved register and the caller checks it; swift_willThrow is nothing more than a one-instruction hook function that exists purely so debuggers can break on it. So in Swift, using throws for a routine, expected condition (“this path is not a symlink”, EINVAL) is completely idiomatic and costs essentially nothing. Apple has no correctness or performance reason to avoid it, and never will.
  2. The API contract forces it. FileManager.destinationOfSymbolicLink(atPath:) is declared throws and is specified to throw when the item is not a symbolic link. +[NSFileAttributes attributesAtPath:traverseLink:] calls it speculatively and swallows the error — which is exactly how you’re supposed to consume that API. Everything behaves as documented.
  3. Where you can legitimately call it a wart. Doing a readlink-style query and throwing away the error, on every directory-enumerator creation, when a single lstat would have answered the same question without an error path, is sloppy in the same way that the extra String → fileSystemRepresentation bridging (also throws) is. It’s a consequence of the ongoing Objective-C→Swift re-implementation of Foundation (macOS 13/14+): the old ObjC code returned nil/errno, the new Swift bridge throws, and the ObjC compatibility shim on top has to convert back. Before that rewrite this stack simply didn’t produce a throw.
    […]
  4. The actual “bug”, if any, is the tooling default. LLDB/CLion’s “Any exception” breakpoint lumps swift_willThrow together with __cxa_throw and objc_exception_throw. For C++ that breakpoint is meaningful (a throw is by definition exceptional); for Swift it is not, because throws is ordinary error return. Breaking on every Swift error in Apple’s frameworks is therefore a false positive by construction — you’ll see the same noise from NSURL, NSBundle, UserDefaults, plist loading, etc., as more of Foundation/AppKit gets rewritten.

One suggestion claude then had was migraring the JUCE Mac File implementation to the POSIX implementations used on Linux where possible instead of using the native Obj-C functions. I’m undecided if I share that opinion, on the other hand past debugging sessions where annyoing enough so that I consider going that route on our in-house JUCE fork. Are there any thoughts from the JUCE developers on this? I’m especially wondering if false swift exceptions from Apple Obj-C code, stopping LLDB become a more and more annyoing thing once Apple rewrites more of its Foundation library?