Closed DanielEdrisian closed 6 years ago
Same here :( This simple Array index out of range crashes
SwiftTryCatch.try({
var array = ["test"]
var wrongThing = array[1]
}, catch: { (error) -> Void in
println("\(error.description)")
}, finally: {
println("finally")
})
you need to change the method signature, it shouldn't include language reserved words.
This worked for me: in the header: +(void)tryRun:(void (^)())tryRun catchRun:(void (^)(NSException *))catchRun finallyRun:(void (^)())finallyRun;
in the implementation: +(void)tryRun:(void (^)())tryRun catchRun:(void (^)(NSException ))catchRun finallyRun:(void (^)())finallyRun { @try { tryRun ? tryRun() : nil; } @catch (NSException exception) { catchRun ? catchRun(exception) : nil; } @finally { finallyRun ? finallyRun() : nil; } }
in swift code:
SwiftTryCatch.tryRun({ // code to try }, catchRun: { (error) in // code to handle exception }, finallyRun: { // code to do any way })
In the try code i still get an exception and the app crashes instead of doing the code in catch. PleAse hElp mE