• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Process.launch() in Swift
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Process.launch() in Swift


  • Subject: Re: Process.launch() in Swift
  • From: Jens Alfke <email@hidden>
  • Date: Wed, 31 May 2017 09:17:55 -0700

> On May 31, 2017, at 8:01 AM, David Catmull <email@hidden> 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@hidden)

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:

This email sent to email@hidden

References: 
 >Process.launch() in Swift (From: David Catmull <email@hidden>)

  • Prev by Date: Process.launch() in Swift
  • Next by Date: switching text field between editable and non-editable
  • Previous by thread: Process.launch() in Swift
  • Next by thread: switching text field between editable and non-editable
  • Index(es):
    • Date
    • Thread