Latest 0.0.3
Homepage https://github.com/joesus/NoExceptions
License MIT
Platforms ios 8.0, osx 10.9, tvos 9.0, requires ARC
Authors ,







This is a library that provides the ability for Swift code to catch an NSException.

This is useful since the standard try and catch mechanism provided by Swift will not capture an NSException thrown from Objective-C.

Syntax

Presuming an Objective-C method that can throw an instance of NSException as shown in the example of MyClass below, the second example would allow for catching the exception in a Swift Error type that wraps it.

@interface MyClass: NSObject

- (void)throwingMethod;
- (id)throwingGetter;

@end
try? trapping(trappable: myObject.throwingMethod)
try? trapping { myObject.throwingMethod() }
let foo = try? trapping { myObject.throwingGetter() }
try? trapping { let bar = myObject.throwingGetter() }
let baz = try? trapping(trappable: myObject.throwingGetter)

do {
    try trapping { myObject.throwingMethod() }
    let variable = try trapping { myObject.throwingGetter() }
    try trapping { let bar = myObject.throwingGetter() }
}
catch error as NSExceptionError {
    /// handle error containing exception
}

Latest podspec

{
    "name": "NoExceptions",
    "version": "0.0.3",
    "summary": "This is a library that provides the ability for Swift code to catch an `NSException`",
    "description": "This is a library that provides the ability for Swift code to catch an `NSException`.nnThis is useful since the standard `try` and `catch` mechanism provided by Swift will not capture an `NSException` thrown from Objective-C.",
    "homepage": "https://github.com/joesus/NoExceptions",
    "license": "MIT",
    "authors": {
        "joesus": "[email protected]",
        "samodom": "[email protected]"
    },
    "platforms": {
        "ios": "8.0",
        "osx": "10.9",
        "tvos": "9.0"
    },
    "source": {
        "git": "https://github.com/joesus/NoExceptions.git",
        "tag": "v0.0.3"
    },
    "source_files": "NoExceptions/*.{h,m,swift}",
    "swift_version": "5.0",
    "requires_arc": true
}

Pin It on Pinterest

Share This