Xcode-beta (7A176x): Add Syntax In Swift To Return Nil On Exceptions

Originator:john
Number:rdar://22189974 Date Originated:07-Aug-2015 01:25 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode-beta (7A176x)
Classification:Feature (New) Reproducible:Always
 
Summary:
There is a feature in Swift 2 to escalate exceptions to fatal errors. I think it would be helpful to have a feature to downgrade exceptions to nil. For instance, the syntax could be:

  let x = try? foo()

With the same semantics as:

  let x: T?
  do { let x = try foo() }
  catch { x = nil }

This syntax would nicely parallel the try! syntax for escalating them to fatal errors, and could reduce the boiler plate when calling an exception-throwing method where the caller doesn’t care about the exception and doesn’t need the value if there’s an exception.

Steps to Reproduce:

Expected Results:

Actual Results:

Regression:

Notes:

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!