Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-10715] Throwing error in defer statement causes error. #419

Closed
purpleblues opened this issue May 18, 2019 · 2 comments
Closed

[SR-10715] Throwing error in defer statement causes error. #419

purpleblues opened this issue May 18, 2019 · 2 comments
Labels
bug Something isn't working

Comments

@purpleblues
Copy link

Previous ID SR-10715
Radar None
Original Reporter @purpleblues
Type Bug
Status Closed
Resolution Invalid
Environment

Xcode 10.2.1 (10E1001), Swift 5.0.1

Additional Detail from JIRA
Votes 0
Component/s Compiler, SwiftSyntax
Labels Bug
Assignee None
Priority Medium

md5: 0fb6eeb45ceff944eb03fa01e6941e17

Issue Description:

Please checkout the code below.

import Foundation

func test(_ work: () throws -> Void) throws {
    try work()
}

do {
    try test {
        
/* Error is not handled because the enclosing function is not declared 'throws' */
        defer { throw NSError(domain: "", code: 0, userInfo: nil) }
        
        print("hello")
    }
    
} catch {
     print(error.localizedDescription)
}

This code emits error that says "Error is not handled because the enclosing function is not declared 'throws'" for throwing in defer statement.

@theblixguy
Copy link
Contributor

You can’t throw inside a defer block. I changed the diagnostic a while ago on master to “'throw' cannot transfer control out of a defer statement”.

@purpleblues
Copy link
Author

Thanks Srijan.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 9, 2022
adevress pushed a commit to adevress/swift-syntax that referenced this issue Jan 14, 2024
Pass `SwiftFormatRules` sources as inputs to `generate-pipeline-plugin`.
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants