Skip to content

Commit 268d36d

Browse files
committed
Add ChangeLog entry for SE-0413: Typed Throws
1 parent b9c5aca commit 268d36d

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

CHANGELOG.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,49 @@
33
> **Note**\
44
> This is in reverse chronological order, so newer entries are added to the top.
55
6+
## Swift 5.11
7+
8+
* [SE-0413][]:
9+
10+
Functions can now specify the type of error that they throw as part of the
11+
function signature. For example:
12+
13+
```swift
14+
func parseRecord(from string: String) throws(ParseError) -> Record { ... }
15+
```
16+
17+
A call to `parseRecord(from:)` will either return a `Record` instance or throw
18+
an error of type `ParseError`. For example, a `do..catch` block will infer
19+
the `error` variable as being of type `ParseError`:
20+
21+
```swift
22+
do {
23+
let record = try parseRecord(from: myString)
24+
} catch {
25+
// error has type ParseError
26+
}
27+
```
28+
29+
Typed throws generalizes over throwing and non-throwing functions. A function
30+
that is specified as `throws` (without an explicitly-specified error type) is
31+
equivalent to one that specifies `throws(any Error)`, whereas a non-throwing
32+
is equivalent to one that specifies `throws(Never)`. Calls to functions that
33+
are `throws(Never)` are non-throwing.
34+
35+
Typed throws can also be used in generic functions to propagate error types
36+
from parameters, in a manner that is more precise than `rethrows`. For
37+
example, the `Sequence.map` operation can propagate the thrown error type from
38+
its closure parameter, indicating that it only throws errors of the same type
39+
as that closure does:
40+
41+
```swift
42+
extension Sequence {
43+
func map<T, E>(_ body: (Element) throws(E) -> T) throws(E) -> [T] { ... }
44+
}
45+
```
46+
47+
When given a non-throwing closure as a parameter, `map` will not throw.
48+
649
* [#70065][]:
750

851
With the implementation of [SE-0110][], a closure parameter syntax consisting
@@ -9861,6 +9904,7 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
98619904
[SE-0394]: https://github.com/apple/swift-evolution/blob/main/proposals/0394-swiftpm-expression-macros.md
98629905
[SE-0397]: https://github.com/apple/swift-evolution/blob/main/proposals/0397-freestanding-declaration-macros.md
98639906
[SE-0407]: https://github.com/apple/swift-evolution/blob/main/proposals/0407-member-macro-conformances.md
9907+
[SE-0413]: https://github.com/apple/swift-evolution/blob/main/proposals/0413-typed-throws.md
98649908
[#64927]: <https://github.com/apple/swift/issues/64927>
98659909
[#42697]: <https://github.com/apple/swift/issues/42697>
98669910
[#42728]: <https://github.com/apple/swift/issues/42728>

0 commit comments

Comments
 (0)