Regression in rethrows in 9.0?

This code works fine in an XCode 8 playground, or in Fire 8.3.2031:

print("The magic happens here.")

func hello( _ callback: () throws -> () ) rethrows
{
	try callback()
}

hello()
{
	print("I dont throw")
}

You don’t need a try on calling hello if the closure doesnt throw.

However, in FIre 9.0.2071, with a java console project, you get:

here it is happy in a playground

Hmm, since hello() is declared to (re)throw, why should a try not be required? seems legit correct to me, unless i’m missing something.

The point of rethrows, as opposed to just throws, is that it only throws iff it’s parameter throws. It effectively passes throughs the throw-iness of the closure. qThis is extrememly useful in declaring utility functions which take a closure/callback. I have it on a synchronised() function, for example.

The doco is here:

https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Declarations.html

Rethrowing Functions and Methods

A function or method can be declared with the rethrows keyword to indicate that it throws an error only if one of its function parameters throws an error. These functions and methods are known as rethrowing functions and rethrowing methods. Rethrowing functions and methods must have at least one throwing function parameter.

func someFunction(callback: () throws -> Void) rethrows {
try callback()
}

A rethrowing function or method can contain a throw statement only inside a catch clause. This lets you call the throwing function inside a do-catch block and handle errors in the catch clause by throwing a different error. In addition, the catch clause must handle only errors thrown by one of the rethrowing function’s throwing parameters. For example, the following is invalid because the catch clause would handle the error thrown by alwaysThrows().

func alwaysThrows() throws {
throw SomeError.error
}
func someFunction(callback: () throws -> Void) rethrows {
do {
try callback()
try alwaysThrows() // Invalid, alwaysThrows() isn’t a throwing parameter
} catch {
throw AnotherError.error
}
}

A throwing method can’t override a rethrowing method, and a throwing method can’t satisfy a protocol requirement for a rethrowing method. That said, a rethrowing method can override a throwing method, and a rethrowing method can satisfy a protocol requirement for a throwing method.

Thanks, logged as bugs://76885

bugs://76885 got closed with status fixed.

this seems to work fine now.