[swift-evolution] Pitch: Replacement for Process
cocoadev at charlessoft.com
Tue Feb 14 11:08:14 CST 2017
> On Feb 14, 2017, at 10:23 AM, Charlie Monroe <charlie at charliemonroe.net> wrote:
>> On Feb 14, 2017, at 4:37 PM, Charles Srstka via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> In Swift 3, NSTask was renamed to Process, making it the de facto API for spawning external tasks in Swift applications. Unfortunately, NSTask uses Objective-C exceptions to report runtime errors in spawning external tasks, which cannot be caught from Swift code.
> I know this may be OOT, but I've solved these for the time being by creating an ObjC class "ExceptionCatcher" that you can call with a block to be executed and one for catching an exception and it will catch the exception for you and pass it to the Swift block handling the exception. This can further be crafted in Swift so that the exception is Swift-thrown as an ExceptionError. But I agree this is a fairly ugly workaround and you need to be aware which methods can actually throw and exception.
I’ve done a little of that, too. Mostly, though, I use custom replacements of my own that I wrote in Objective-C years ago. It’d be nice if there were something standardized, though.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution