williamFalcon / SwiftTryCatch

Adds try-catch support for Swift
MIT License
140 stars 58 forks source link

Crashes when unwrapping optional #2

Closed zackprice closed 9 years ago

zackprice commented 9 years ago

Quite possibly i'm "doing this wrong", but I can still make it crash really easily.

Am I calling it wrong? Is there another way I can use it? Thanks!

func crash(){
    SwiftTryCatch.try({ () -> Void in
        // this is an invalid url and will crash.  In the real world, a url with a space _ in it makes NSURL angry)
      var  url = NSURL(string: " _ ")!

        }, catch: { (error) -> Void in
            println("the whole thing crashed")
        }, finally: { () -> Void in
            //close resources
    })
}
cfr commented 9 years ago

That's actually not an exception but a EXC_BAD_ACCESS crash in Swift code. Try this one instead of NSURL:

NSException.raise("", format: "", arguments: getVaList(["nil"]))

Check out Matt Gallagher post on handling unhandled exceptions and signals.