Skip to content

Commit beb846f

Browse files
committed
docs/README.md: fix outdated links
1 parent 2a6570e commit beb846f

File tree

2 files changed

+56
-54
lines changed

2 files changed

+56
-54
lines changed

docs/ErrorHandling.md

Lines changed: 53 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ manipulating recoverable error conditions.
88
Error handling is a well-trod path, with many different approaches in
99
other languages, many of them problematic in various ways. We believe
1010
that our approach provides an elegant solution, drawing on the lessons
11-
we\'ve learned from other languages and fixing or avoiding some of the
11+
we've learned from other languages and fixing or avoiding some of the
1212
pitfalls. The result is expressive and concise while still feeling
1313
explicit, safe, and familiar; and we believe it will work beautifully
1414
with the Cocoa APIs.
1515

16-
We\'re intentionally not using the term \"exception handling\", which
16+
We're intentionally not using the term "exception handling", which
1717
carries a lot of connotations from its use in other languages. Our
1818
proposal has some similarities to the exceptions systems in those
1919
languages, but it also has a lot of important differences.
2020

2121
## Kinds of Error
2222

23-
What exactly is an \"error\"? There are many possible error conditions,
24-
and they don\'t all make sense to handle in exactly the same way,
23+
What exactly is an "error"? There are many possible error conditions,
24+
and they don't all make sense to handle in exactly the same way,
2525
because they arise in different circumstances and programmers have to
2626
react to them differently.
2727

@@ -30,22 +30,22 @@ severity:
3030

3131
A **simple domain error** arises from an operation that can fail in some
3232
obvious way and which is often invoked speculatively. Parsing an integer
33-
from a string is a really good example. The client doesn\'t need a
33+
from a string is a really good example. The client doesn't need a
3434
detailed description of the error and will usually want to handle the
3535
error immediately. These errors are already well-modeled by returning an
36-
optional value; we don\'t need a more complex language solution for
36+
optional value; we don't need a more complex language solution for
3737
them.
3838

3939
A **recoverable error** arises from an operation which can fail in
4040
complex ways, but whose errors can be reasonably anticipated in advance.
4141
Examples including opening a file or reading from a network connection.
42-
These are the kinds of errors that Apple\'s APIs use NSError for today,
42+
These are the kinds of errors that Apple's APIs use NSError for today,
4343
but there are close analogues in many other APIs, such as `errno` in
4444
POSIX.
4545

4646
Ignoring this kind of error is usually a bad idea, and it can even be
4747
dangerous (e.g. by introducing a security hole). Developers should be
48-
strongly encouraged to write code that handles the error. It\'s common
48+
strongly encouraged to write code that handles the error. It's common
4949
for developers to want to handle errors from different operations in the
5050
same basic way, either by reporting the error to the user or passing the
5151
error back to their own clients.
@@ -54,7 +54,7 @@ These errors will be the focus of this proposal.
5454

5555
The final two classes of error are outside the scope of this proposal. A
5656
**universal error** is theoretically recoverable, but by its nature the
57-
language can\'t help the programmer anticipate where it will come from.
57+
language can't help the programmer anticipate where it will come from.
5858
A **logic failure** arises from a programmer mistake and should not be
5959
recoverable at all. In our system, these kinds of errors are reported
6060
either with Objective-C/C++ exceptions or simply by logging a message
@@ -77,13 +77,13 @@ Notably, the approach preserves these advantages of this convention:
7777
and a simple inspection reveals how the function reacts to the
7878
error.
7979
- Throwing an error provides similar performance to allocating an
80-
error and returning it \-- it isn\'t an expensive, table-based stack
80+
error and returning it \-- it isn't an expensive, table-based stack
8181
unwinding process.
8282
- Cocoa APIs using standard `NSError` patterns can be imported into
8383
this world automatically. Other common patterns (e.g. `CFError`,
8484
`errno`) can be added to the model in future versions of Swift.
8585

86-
In addition, we feel that this design improves on Objective-C\'s error
86+
In addition, we feel that this design improves on Objective-C's error
8787
handling approach in a number of ways:
8888

8989
- It eliminates a lot of boilerplate control-flow code for propagating
@@ -98,25 +98,25 @@ exception handling. We considered intentionally using different terms
9898
(like `raise` / `handle`) to try to distinguish our approach from other
9999
languages. However, by and large, error propagation in this proposal
100100
works like it does in exception handling, and people are inevitably
101-
going to make the connection. Given that, we couldn\'t find a compelling
101+
going to make the connection. Given that, we couldn't find a compelling
102102
reason to deviate from the `throw` / `catch` legacy.
103103

104104
This document just contains the basic proposal and will be very light on
105105
rationale. We considered many different languages and programming
106-
environments as part of making this proposal, and there\'s an extensive
106+
environments as part of making this proposal, and there's an extensive
107107
discussion of them in the separate rationale document. For example, that
108-
document explains why we don\'t simply allow all functions to throw, why
109-
we don\'t propagate errors using simply an `ErrorOr<T>` return type, and
110-
why we don\'t just make error propagation part of a general monad
111-
feature. We encourage you to read that rationale if you\'re interested
108+
document explains why we don't simply allow all functions to throw, why
109+
we don't propagate errors using simply an `ErrorOr<T>` return type, and
110+
why we don't just make error propagation part of a general monad
111+
feature. We encourage you to read that rationale if you're interested
112112
in understanding why we made the decisions we did.
113113

114-
With that out of the way, let\'s get to the details of the proposal.
114+
With that out of the way, let's get to the details of the proposal.
115115

116116
## Typed propagation
117117

118118
Whether a function can throw is part of its type. This applies to all
119-
functions, whether they\'re global functions, methods, or closures.
119+
functions, whether they're global functions, methods, or closures.
120120

121121
By default, a function cannot throw. The compiler statically enforces
122122
this: anything the function does which can throw must appear in a
@@ -126,7 +126,7 @@ A function can be declared to throw by writing `throws` on the function
126126
declaration or type:
127127

128128
```swift
129-
func foo() -> Int { // This function is not permitted to throw.
129+
func foo() -> Int { // This function is not permitted to throw.
130130
func bar() throws -> Int { // This function is permitted to throw.
131131
```
132132

@@ -156,7 +156,7 @@ func jerry(_ i: Int)(j: Int) throws -> Int {
156156

157157
`throws` is tracked as part of the type system: a function value must
158158
also declare whether it can throw. Functions that cannot throw are a
159-
subtype of functions that can, so you can use a function that can\'t
159+
subtype of functions that can, so you can use a function that can't
160160
throw anywhere you could use a function that can:
161161

162162
```swift
@@ -172,7 +172,7 @@ handle the error.
172172
A call to a function which can throw within a context that is not
173173
allowed to throw is rejected by the compiler.
174174

175-
It isn\'t possible to overload functions solely based on whether the
175+
It isn't possible to overload functions solely based on whether the
176176
functions throw. That is, this is not legal:
177177

178178
```swift
@@ -227,13 +227,15 @@ a direct call to a `rethrows` function is considered to not throw if it
227227
is fully applied and none of the function arguments can throw. For
228228
example:
229229
230-
// This call to map is considered not to throw because its
231-
// argument function does not throw.
232-
let absolutePaths = paths.map { "/" + $0 }
230+
```swift
231+
// This call to map is considered not to throw because its
232+
// argument function does not throw.
233+
let absolutePaths = paths.map { "/" + $0 }
233234
234-
// This call to map is considered to throw because its
235-
// argument function does throw.
236-
let streams = try absolutePaths.map { try InputStream(filename: $0) }
235+
// This call to map is considered to throw because its
236+
// argument function does throw.
237+
let streams = try absolutePaths.map { try InputStream(filename: $0) }
238+
```
237239
238240
For now, `rethrows` is a property of declared functions, not of function
239241
values. Binding a variable (even a constant) to a function loses the
@@ -345,7 +347,7 @@ scopes (that permit it), rather than relying on the programmer to
345347
manually check for errors and do their own control flow. This is just a
346348
lot less boilerplate for common error handling tasks. However, doing
347349
this naively would introduce a lot of implicit control flow, which makes
348-
it difficult to reason about the function\'s behavior. This is a serious
350+
it difficult to reason about the function's behavior. This is a serious
349351
maintenance problem and has traditionally been a considerable source of
350352
bugs in languages that heavily use exceptions.
351353
@@ -378,7 +380,7 @@ func readStuff() throws {
378380
}
379381
```
380382
381-
Developers can choose to \"scope\" the `try` very tightly by writing it
383+
Developers can choose to "scope" the `try` very tightly by writing it
382384
within parentheses or on a specific argument or list element:
383385
384386
```swift
@@ -395,7 +397,7 @@ let array = [ try foo(), bar(), baz() ]
395397
396398
Some developers may wish to do this to make the specific throwing calls
397399
very clear. Other developers may be content with knowing that something
398-
within a statement can throw. The compiler\'s fixit hints will guide
400+
within a statement can throw. The compiler's fixit hints will guide
399401
developers towards inserting a single `try` that covers the entire
400402
statement. This could potentially be controlled someday by a coding
401403
style flag passed to the compiler.
@@ -411,7 +413,7 @@ expression is considered to handle any error originating from within its
411413
operand.
412414
413415
`try!` is otherwise exactly like `try`: it can appear in exactly the
414-
same positions and doesn\'t affect the type of an expression.
416+
same positions and doesn't affect the type of an expression.
415417
416418
## Manual propagation and manipulation of errors
417419
@@ -430,7 +432,7 @@ As such, the Swift standard library should provide a standard Rust-like
430432
propagating the error in the current context.
431433
432434
This is something that composes on top of the basic model, but that has
433-
not been designed yet and details aren\'t included in this proposal.
435+
not been designed yet and details aren't included in this proposal.
434436
435437
The name `Result<T>` is a stand-in and needs to be designed and
436438
reviewed, as well as the basic operations on the type.
@@ -488,7 +490,7 @@ based on real-world usage experience.
488490
489491
## Importing Cocoa
490492
491-
If possible, Swift\'s error-handling model should transparently work
493+
If possible, Swift's error-handling model should transparently work
492494
with the SDK with a minimal amount of effort from framework owners.
493495
494496
We believe that we can cover the vast majority of Objective-C APIs with
@@ -521,7 +523,7 @@ couple of simple heuristics:
521523
- Also common is a pointer result, where a `nil` result usually means
522524
an error occurred. This appears to be universal in Objective-C; APIs
523525
that can return `nil` results seem to do so via out-parameters. So
524-
it seems to be safe to make a policy decision that it\'s okay to
526+
it seems to be safe to make a policy decision that it's okay to
525527
assume that a `nil` result is an error by default.
526528
527529
If the pattern for a method is that a `nil` result means it produced
@@ -534,7 +536,7 @@ For other sentinel cases, we can consider adding a new clang attribute
534536
to indicate to the compiler what the sentinel is:
535537
536538
- There are several APIs returning `NSInteger` or `NSUInteger`. At
537-
least some of these return 0 on error, but that doesn\'t seem like a
539+
least some of these return 0 on error, but that doesn't seem like a
538540
reasonable general assumption.
539541
- `AVFoundation` provides a couple methods returning
540542
`AVKeyValueStatus`. These produce an error if the API returned
@@ -564,16 +566,16 @@ just Swift. (For example, they could try to detect an invalid error
564566
check.)
565567
566568
Cases that do not match the automatically imported patterns and that
567-
lack an attribute would be left unmodified (i.e., they\'d keep their
568-
NSErrorPointer argument) and considered \"not awesome\" in the SDK
569+
lack an attribute would be left unmodified (i.e., they'd keep their
570+
NSErrorPointer argument) and considered "not awesome" in the SDK
569571
auditing tool. These will still be usable in Swift: callers will get the
570572
NSError back like they do today, and have to throw the result manually.
571573
572574
For initializers, importing an initializer as throwing takes precedence
573575
over importing it as failable. That is, an imported initializer with a
574576
nullable result and an error parameter would be imported as throwing.
575577
Throwing initializers have very similar constraints to failable
576-
initializers; in a way, it\'s just a new axis of failability.
578+
initializers; in a way, it's just a new axis of failability.
577579
578580
One limitation of this approach is that we need to be able to
579581
reconstruct the selector to use when an overload of a method is
@@ -624,15 +626,15 @@ This would be imported as:
624626
func validateForDelete() throws
625627
```
626628
627-
This is a really nice import, and it\'s somewhat unfortunate that we
628-
can\'t import `duplicateAndReturnError:` as `duplicate()`.
629+
This is a really nice import, and it's somewhat unfortunate that we
630+
can't import `duplicateAndReturnError:` as `duplicate()`.
629631
630632
## Potential future extensions to this model
631633
632634
We believe that the proposal above is sufficient to provide a huge step
633635
forward in error handling in Swift programs, but there is always more to
634-
consider in the future. Some specific things we\'ve discussed (and may
635-
come back to in the future) but don\'t consider to be core to the Swift
636+
consider in the future. Some specific things we've discussed (and may
637+
come back to in the future) but don't consider to be core to the Swift
636638
2.0 model are:
637639
638640
### Higher-order polymorphism
@@ -649,7 +651,7 @@ func map<T, U>(_ array: [T], fn: T -> U) throwsIf(fn) -> [U] {
649651
}
650652
```
651653
652-
There\'s no need for a more complex logical operator than disjunction
654+
There's no need for a more complex logical operator than disjunction
653655
for normal higher-order stuff.
654656
655657
This feature is highly desired (e.g. it would allow many otherwise
@@ -682,14 +684,14 @@ autoreleasepool {
682684
}
683685
```
684686
685-
The error-handling model doesn\'t cause major problems for this. The
687+
The error-handling model doesn't cause major problems for this. The
686688
compiler can infer that the closure throws, and `autoreleasepool` can be
687689
overloaded on whether its argument closure throws; the overload that
688690
takes a throwing closures would itself throw.
689691
690692
There is one minor usability problem here, though. If the closure
691693
contains throwing expressions, those expressions must be explicitly
692-
marked within the closure with `try`. However, from the compiler\'s
694+
marked within the closure with `try`. However, from the compiler's
693695
perspective, the call to `autoreleasepool` is also a call that can
694696
throw, and so it must also be marked with `try`:
695697
@@ -702,10 +704,10 @@ try autoreleasepool { // 'try' is required here...
702704
703705
This marking feels redundant. We want functions like `autoreleasepool`
704706
to feel like statements, but marks inside built-in statements like `if`
705-
don\'t require the outer statement to be marked. It would be better if
706-
the compiler didn\'t require the outer `try`.
707+
don't require the outer statement to be marked. It would be better if
708+
the compiler didn't require the outer `try`.
707709
708-
On the other hand, the \"statement-like\" story already has a number of
710+
On the other hand, the "statement-like" story already has a number of
709711
other holes: for example, `break`, `continue`, and `return` behave
710712
differently in the argument closure than in statements. In the future,
711713
we may consider fixing that; that fix will also need to address the
@@ -727,9 +729,9 @@ here: 1) the memory management rules for CFErrors are unclear and
727729
potentially inconsistent. 2) we need to know when an error is raised.
728730
729731
In principle, we could import POSIX functions into Swift as throwing
730-
functions, filling in the error from `errno`. It\'s nearly impossible to
732+
functions, filling in the error from `errno`. It's nearly impossible to
731733
imagine doing this with an automatic import rule, however; much more
732-
likely, we\'d need to wrap them all in an overlay.
734+
likely, we'd need to wrap them all in an overlay.
733735
734736
In both cases, it is possible to pull these into the Swift error
735737
handling model, but because this is likely to require massive SDK

docs/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ documentation, please create a thread on the Swift forums under the
215215

216216
### Coding
217217

218-
- [AccessControlInStdlib.rst](/docs/AccessControlInStdlib.rst):
218+
- [AccessControlInStdlib.md](/docs/AccessControlInStdlib.md):
219219
Describes the policy for access control modifiers and related naming
220220
conventions in the stdlib.
221221
<!-- NOTE: Outdated -->
@@ -290,10 +290,10 @@ documentation, primarily [The Swift Programming Language][] (TSPL).
290290
They are preserved mostly for historical interest.
291291

292292
- [AccessControl.md](/docs/AccessControl.md)
293-
- [Arrays.rst](/docs/Arrays.rst)
293+
- [Arrays.md](/docs/Arrays.md)
294294
<!-- Has additional notes on bridging that may be of general interest? -->
295295
- [Generics.rst](/docs/Generics.rst)
296-
- [ErrorHandling.rst](/docs/ErrorHandling.rst)
296+
- [ErrorHandling.md](/docs/ErrorHandling.md)
297297
- [StringDesign.rst](/docs/StringDesign.rst)
298298
- [TextFormatting.rst](/docs/TextFormatting.rst)
299299

0 commit comments

Comments
 (0)