> On Feb 14, 2017, at 10:23 AM, Charlie Monroe <[email protected]> 
> wrote:
> 
>> On Feb 14, 2017, at 4:37 PM, Charles Srstka via swift-evolution 
>> <[email protected] <mailto:[email protected]>> wrote:
>> 
>> MOTIVATION:
>> 
>> 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.

Charles

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to