Skip to content

Conversation

Alex-Timakov
Copy link

@Alex-Timakov Alex-Timakov commented Mar 20, 2025

The Swift documentation contains an incorrect function declaration in the Error Handling section:
The throws modifier should be before { and not after ->.

Current (incorrect) code:

func someThrowingFunction() -> throws 
func someThrowingFunction() -> throws(any Error)

Fix:

func someThrowingFunction() throws 
func someThrowingFunction() throws(any Error)

Documentation Link:
https://docs.swift.org/swift-book/documentation/the-swift-programming-language/errorhandling#Specifying-the-Error-Type
Issue Link:
#360

Similar Pull-Request:
#358

Copy link
Member

@amartini51 amartini51 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed that compiling the code without this fix produces the expected error: 'throws' may only occur before '->'.

Confirmed that this is the only place in the book where this error appears:

% git grep -- '-> throws'
LanguageGuide/ErrorHandling.md:func someThrowingFunction() -> throws {
LanguageGuide/ErrorHandling.md:func someThrowingFunction() -> throws(any Error) {

Thanks for the correction!

@amartini51 amartini51 merged commit d4b33e2 into swiftlang:main Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect throws syntax in Swift documentation (Error Handling section)
3 participants