Closure erroneously inferred as "throws" when catching as NSError

Originator:fluidsonic
Number:rdar://21669303 Date Originated:2015-07-03
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 7 Beta 2
Classification:Other Bug Reproducible:Always
 
Summary:
When using "catch as NSError" in a regular function then the catch clause is considered exhaustive.
When using "catch as NSError" in a closure then the closure is inferred as "throws" because the catch is NOT considered exhaustive.

This results in the following compilation error when calling or passing the closure: "call can throw, but it is not marked with 'try' and the error is not handled"

Steps to Reproduce:
1. Copy attached example code into a Playground
2. You'll get the error "call can throw, but it is not marked with 'try' and the error is not handled"

Expected Results:
"catch as NSError" should be considered exhaustive and the closure not be marked as "throws".

Actual Results:
The closure is erroneously inferred as "throws"


Attached file:

import Foundation

func funcWhichThrows() throws {}

func testWithClosure() {
	{ () -> Void in
		do {
			try funcWhichThrows()
		}
		catch _ as NSError {
			// catch all as NSError
		}
	}()
}

func testWithoutClosure() {
	do {
		try funcWhichThrows()
	}
	catch _ as NSError {
		// catch all as NSError
	}
}

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!