Skip to content

Commit dbfe725

Browse files
amartini51Rebecca Teibloom
andcommitted
Start incorporating editorial feedback
Edits from <rdar://125975390> Co-authored-by: Rebecca Teibloom <[email protected]>
1 parent 356f018 commit dbfe725

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

TSPL.docc/LanguageGuide/ErrorHandling.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,9 @@ you don't know ahead of time every error that could happen
709709
while the code is running,
710710
especially when propagating errors thrown somewhere else.
711711
This approach also reflects the fact that errors can change over time.
712-
New versions of a library can throw new errors ---
713-
including libraries used by your dependencies ---
712+
New versions of a library ---
713+
including libraries that your dependencies use ---
714+
can throw new errors,
714715
and the rich complexity of real-world user configurations
715716
can expose failure modes that weren't visible during development or testing.
716717
The error handling code in the examples above
@@ -719,26 +720,26 @@ that don't have their own specific `catch` clause.
719720

720721
Most Swift code doesn't specify the type for the errors it throws.
721722
However,
722-
in some special cases,
723-
you might limit code to throwing errors of only one specific type:
723+
you might limit code to throwing errors of only one specific type
724+
in the following special cases:
724725

725726
- When running code on an embedded system
726727
that doesn't support dynamic allocation of memory.
727-
Throwing an instance `any Error` or another boxed protocol type
728+
Throwing an instance of `any Error` or another boxed protocol type
728729
requires allocating memory at runtime to store the error.
729730
Throwing an error of a specific type
730731
lets Swift allocate that memory upfront instead.
731732

732733
- When the errors are used only within some unit of code,
733734
like a library,
734735
and aren't part of the interface to that code.
735-
Because the errors come only from the library,
736+
Because the errors come from only the library,
736737
and not from other dependencies or the library's clients,
737738
you can make an exhaustive list of all possible failures.
738739
And because these errors are an implementation detail of the library,
739-
and they're always handled within that library.
740+
they're always handled within that library.
740741

741-
- In code that only throws errors that were thrown elsewhere,
742+
- In code that throws only errors that were thrown elsewhere,
742743
like a function that takes a closure argument
743744
and propagates any errors from that closure.
744745
For a comparison between `rethrows`
@@ -756,9 +757,9 @@ enum StatisticsError: Error {
756757
}
757758
```
758759

759-
To specify that a function throws only `StatisticsError` values as its errors
760-
you write `throws(StatisticsError)` when declaring the function,
761-
instead of just writing `throws`.
760+
To specify that a function throws only `StatisticsError` values as its errors,
761+
you write `throws(StatisticsError)` instead of only `throws`
762+
when declaring the function.
762763
This syntax is also called *typed throws*
763764
because you write the error type after `throws` --- for example:
764765

@@ -783,7 +784,7 @@ This function throws an instance of `StatisticsError` if the input isn't valid.
783784
Both places in the code above that throw an error
784785
omit the type of the error
785786
because the function's error type is already defined.
786-
You can use the short form like `throw .noRatings`
787+
You can use the short form, `throw .noRatings`,
787788
instead of writing `throw StatisticsError.noRatings`
788789
when throwing an error in a function like this.
789790

@@ -847,7 +848,7 @@ the `do`-`catch` statement throws `StatisticsError` values as its errors.
847848
Like other `do`-`catch` statements,
848849
the `catch` clause can either handle every possible error,
849850
or it can propagate unhandled errors for some surrounding scope to handle.
850-
Here, it handles all of the errors,
851+
This code handles all of the errors,
851852
using a switch with one case for each enumeration value.
852853
Like other `catch` clauses that don't have a pattern,
853854
the clause matches any error
@@ -867,7 +868,7 @@ For a library that catches all of its own errors,
867868
you could use this approach to ensure any new errors
868869
get corresponding new code to handle them.
869870

870-
If a function or `do` block throws only errors of a single type,
871+
If a function or `do` block throws errors of only a single type,
871872
Swift infers that this code is using typed throws.
872873
Using this shorter syntax,
873874
you could write the `do`-`catch` example above as follows:

TSPL.docc/ReferenceManual/Declarations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,7 @@ 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-
A function's type includes whether it can throw an error,
1479+
A function's type includes whether it can throw an error
14801480
and what type of error it throws.
14811481
This means, for example, you can use a nonthrowing function
14821482
in a context where a throwing one is expected.

TSPL.docc/ReferenceManual/Expressions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,9 +925,9 @@ explicitly marks a closure as throwing or asynchronous.
925925
If the body of a closure includes a `throws` statement or a `try` expression
926926
that isn't nested inside of a `do` statement with exhaustive error handling,
927927
the closure is understood to be throwing.
928-
If a throwing closure throws only errors of a single type,
928+
If a throwing closure throws errors of only a single type,
929929
the closure is understood as throwing that error type;
930-
otherwise it's understood as throwing `any Error`.
930+
otherwise, it's understood as throwing `any Error`.
931931
Likewise, if the body includes an `await` expression,
932932
it's understood to be asynchronous.
933933

TSPL.docc/ReferenceManual/Statements.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ If the `do` statement doesn't specify the type of error it throws,
901901
the error type is inferred as follows:
902902

903903
- If every `throws` statement and `try` expression in the `do` code block
904-
is nested inside of an exhaustive error handling mechanism,
904+
is nested inside of an exhaustive error-handling mechanism,
905905
then the `do` statement is inferred as nonthrowing.
906906

907907
- If the `do` code block contains code that throws

TSPL.docc/ReferenceManual/Types.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ that can throw or rethrow an error must include the `throws` keyword.
352352
You can include a type after `throws` in parentheses
353353
to specify the type of error that the function throws.
354354
The throw error type must conform to the `Error` protocol.
355-
Writing `throws` without specifying an type
355+
Writing `throws` without specifying a type
356356
is the same as writing `throws(any Error)`.
357357
Omitting `throws` is the same as writing `throws(Never)`.
358358
The error type that a function throws
@@ -366,9 +366,9 @@ For example, if you declare a custom `MyError` type,
366366
the relationship between some function types is as follows,
367367
from supertype to subtype:
368368

369-
1. Functions that throw any error, marked `throws(any Error)`.
370-
1. Functions that throw a specific error, marked `throws(MyError)`.
371-
1. Functions that don't throw, marked `throws(Never)`.
369+
1. Functions that throw any error, marked `throws(any Error)`
370+
1. Functions that throw a specific error, marked `throws(MyError)`
371+
1. Functions that don't throw, marked `throws(Never)`
372372

373373
As a result of these subtype relationships:
374374

0 commit comments

Comments
 (0)