Skip to content

Enhancement Request: support for Swift error handling inside trap block #11

@uriah-eisenstein

Description

@uriah-eisenstein

Using Swift 5 on Xcode 10.2: a Swift function which throws, when called inside a trap block, needs be wrapped in its own do { … try … } catch. This is because trap takes a non-throwing block as an argument.

I encountered this, for instance, with NSManagedObjectContext.save – it is a throwing function in Swift, but may also throw an Objective-C exception in case of invalid data or constraint violation.

(I tried making trap accept a throwing function myself, but it turned out not to be trivial, since Swift doesn't automatically translate an Objective-C block parameter taking NSError** into a Swift throwing function. The following link might be useful, I haven't had time to experiment further: https://stackoverflow.com/questions/49324917/swift-try-inside-objective-c-block)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions