> On May 31, 2017, at 8:01 AM, David Catmull <[email protected]> wrote: > > The documentation for Process.launch() (the equivalent of -[NSTask launch]) > says it "raises an NSInvalidArgumentException if the launch path has not > been set or is invalid or if it fails to create a process", and yet the > function is not marked as "throws". So what happens if I call it from Swift > and it encounters an error?
Swift’s ‘throws’ is not the same as Objective-C throwing an exception; rather, it’s the equivalent of Objective-C returning an NSError via an ‘out’ parameter. Swift doesn’t support exceptions at all, so any exception thrown from Obj-C (or C++) will go uncaught and crash the app. NSTask is one of those rare Cocoa APIs that can throw an NSException in normal use, if it “fails to create a process”. It’s been years since I used it so I don’t remember the circumstances where this can occur. But yes, to be safe you would need to call it from Obj-C and wrap an @try block around it to catch and handle the exception before returning to Swift. —Jens _______________________________________________ Cocoa-dev mailing list ([email protected]) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
