Skip to content

Commit 3ea9edd

Browse files
committed
Incorporate feedback from pitch
See also https://forums.swift.org/t/70526
1 parent 3c2816a commit 3ea9edd

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

TSPL.docc/LanguageGuide/ErrorHandling.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,9 @@ XXX OUTLINE XXX
714714
- A boxed protocol (aka existential) type matches the reality of most code.
715715
At compile time, you don't know every possible way things could go wrong.
716716
In particular, some errors will come from calling other throwing functions.
717+
This is why most code uses a boxed protocol type as its error type.
717718

718-
- In contrast, a concrete error type is useful:
719+
- In contrast, a concrete error type is useful in some special circumstances:
719720

720721
* When the code that throws errors
721722
and the code that handles those errors
@@ -726,6 +727,7 @@ XXX OUTLINE XXX
726727

727728
* In code that only rethrows errors,
728729
especially when the throwing code comes from a closure the caller provided.
730+
(However, neither rethrows nor typed throws is a strict superset of the other.)
729731
Example: `map` in the stdlib.
730732
Xref to reference section -- this chapter doesn't discuss rethrows
731733

@@ -742,6 +744,7 @@ XXX OUTLINE XXX
742744
this is still "concrete" in sense that
743745
the errors are all instances of the concrete type
744746
that's hidden behind the opaque type.
747+
And there's still one specific error type.
745748

746749
- To specify the error type for a `do` block or a throwing function,
747750
write `throws(E)` where `E` is an error type.
@@ -753,8 +756,11 @@ XXX OUTLINE XXX
753756

754757
- For a normal error (of boxed protocol type)
755758
the `catch` clause needs to either include a general catch/default
759+
that handles errors whose types the other clauses don't handle,
756760
or to propagate the errors it doesn't handle.
757-
For a typed error, the catch clause can be exhaustive.
761+
For a typed error, the catch clause can be exhaustive
762+
without a default clause
763+
by handling just that specific error type.
758764

759765
XXX RUNNING EXAMPLE XXX
760766

TSPL.docc/ReferenceManual/Declarations.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,12 @@ and a throwing method can't satisfy a protocol requirement for a rethrowing meth
15941594
That said, a rethrowing method can override a throwing method,
15951595
and a rethrowing method can satisfy a protocol requirement for a throwing method.
15961596

1597+
<!-- XXX comparison between rethrows and generic typed throws
1598+
1599+
func f<E: Error>(closure: () throws(E) -> Int) throws(E) -> Int { ... }
1600+
func g(closure: () throws -> Int) rethrows -> Int { ... }
1601+
-->
1602+
15971603
### Asynchronous Functions and Methods
15981604

15991605
Functions and methods that run asynchronously must be marked with the `async` keyword.

0 commit comments

Comments
 (0)