Uploaded image for project: 'Swift'
  1. Swift
  2. SR-10715

Throwing error in defer statement causes error.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Medium
    • Resolution: Invalid
    • Component/s: Compiler, SwiftSyntax
    • Labels:
      None
    • Environment:

      Xcode 10.2.1 (10E1001), Swift 5.0.1

      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.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            crunchbox Sungmin Kim
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: