Can nested do-catch blocks explicitly work?

Using typed throws in Swift 6, you need to explicitly annotate the typed throw for each [edit: at least the outer] do block:

func doStuff<E: Error>(
    with closure: () throws(E) -> Void
) throws(E) -> Void {
    do throws(E) {
        do /* throws(E) */ {
            try closure()
        } catch {
            throw error
        }
    } catch {
        throw error
    }
}

Type inference will change with the FullTypedThrows feature to support this without annotation, but that is not yet available until a future version.

1 Like