Skip to content

Commit ac8a86d

Browse files
committed
Add cross reference
Nothing to add about inferring the error type thrown by a function, because that behavior applies only to closures and do-catch blocks.
1 parent b99d8f4 commit ac8a86d

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

TSPL.docc/ReferenceManual/Declarations.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,16 +1476,14 @@ func <#function name#>(<#parameters#>) throws(<#error type#>) -> <#return type#>
14761476
Calls to a throwing function or method must be wrapped in a `try` or `try!` expression
14771477
(that is, in the scope of a `try` or `try!` operator).
14781478

1479-
<!-- XXX
1480-
Rule for inferring the thrown error type
1481-
Xref to the guide <doc:ErrorHandling#Specifying-a-Concrete-Error-Type>
1482-
-->
1483-
14841479
A function's type includes whether it can throw an error,
14851480
and what type of error it throws.
14861481
This means, for example, you can use a nonthrowing function
14871482
in a context where a throwing one is expected.
1488-
For more information, see <doc:Types#Function-Type>.
1483+
For more information about the type of a throwing function,
1484+
see <doc:Types#Function-Type>.
1485+
For examples of working with errors that have explicit types,
1486+
see <doc:ErrorHandling#Specifying-a-Concrete-Error-Type>.
14891487

14901488
You can't overload a function based only on whether the function can throw an error.
14911489
That said,

TSPL.docc/ReferenceManual/Types.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ that can throw or rethrow an error must include the `throws` keyword.
351351
<!-- XXX TR: Confirm rethrowing functions use 'throws' -->
352352
You can include a type after `throws` in parentheses
353353
to specify the type of error that the function throws.
354+
The throw error type must conform to the `Error` protocol.
354355
Writing `throws` without specifying an type
355356
is the same as writing `throws(any Error)`.
356357
Omitting `throws` is the same as writing `throws(Never)`.

0 commit comments

Comments
 (0)