I am currently writing a Swift 2 application that could throw an error. To prevent it from crashing my code, I am using do
-try
-catch
.
In python we can do something like this:
try:
functionThatThrowsError()
except exceptionOne:
pass # exceptionOne was caught
except exceptionTwo:
pass # exceptionTwo was caught
else:
pass # No Errors in code
I currently have this code in Swift:
do
{
try functionThatThrowsError
} catch exceptionOne {
//Do stuff
} catch exceptionTwo {
//Do Stuff
}
How would I do this in Swift 2?
Edit: The 'posible duplicate' is not a duplicate of Swift do-try-catch syntax since the do-try-except does not check if the code executed successfully.
What I want to do is this:
Run a function that could throw an error
Check for one type of error
Do code if the error happened
Check for another error type that occurred
Do code if that error happened
If the function does not throw an error
Do this code