File tree Expand file tree Collapse file tree 4 files changed +21
-1
lines changed
TSPL.docc/ReferenceManual Expand file tree Collapse file tree 4 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -1468,8 +1468,16 @@ func <#function name#>(<#parameters#>) throws -> <#return type#> {
14681468Calls to a throwing function or method must be wrapped in a ` try ` or ` try! ` expression
14691469(that is, in the scope of a ` try ` or ` try! ` operator).
14701470
1471+ <!-- XXX
1472+ Rule for inferring the thrown error type
1473+ Xref to the guide <doc:ErrorHandling#Specifying-a-Concrete-Error-Type>
1474+ -->
1475+
14711476The ` throws ` keyword is part of a function's type,
14721477and nonthrowing functions are subtypes of throwing functions.
1478+ <!-- XXX
1479+ Subtyping rule for throws(any Error) vs throws(MyErrorType)
1480+ -->
14731481As a result, you can use a nonthrowing function
14741482in a context where a throwing one is expected.
14751483
Original file line number Diff line number Diff line change @@ -924,6 +924,10 @@ explicitly marks a closure as throwing or asynchronous.
924924
925925If the body of a closure includes a try expression,
926926the closure is understood to be throwing.
927+ <!-- XXX
928+ The same rule to infer the thrown error type
929+ applies to closures as to functions.
930+ -->
927931Likewise, if it includes an await expression,
928932it's understood to be asynchronous.
929933
Original file line number Diff line number Diff line change @@ -897,7 +897,7 @@ or the boxed protocol type `any Error`.
897897If the `do` statement doesn't specify the type of error it throws,
898898that type is implied to be `any Error`.
899899For more information about working with errors that have explicit types,
900- see <!-- XXX xref guide -- >.
900+ see <doc: ErrorHandling # Specifying - a - Concrete - Error - Type >.
901901
902902If any statement in the `do` code block throws an error,
903903program control is transferred
Original file line number Diff line number Diff line change @@ -350,6 +350,14 @@ Function types for functions
350350that can throw or rethrow an error must be marked with the ` throws ` keyword.
351351The ` throws ` keyword is part of a function's type,
352352and nonthrowing functions are subtypes of throwing functions.
353+ <!-- XXX
354+ A function that throws a concrete error
355+ is a subtype of one that throws 'any Error'.
356+
357+ TR:
358+ If EE is a subtype of E,
359+ is a function that throws EE a subtype of one that throws E?
360+ -->
353361As a result, you can use a nonthrowing function in the same places as a throwing one.
354362Throwing and rethrowing functions are described in
355363< doc:Declarations#Throwing-Functions-and-Methods >
You can’t perform that action at this time.
0 commit comments