I'm new to Swift and I have a little problem.
I have a piece of code, and any line could potentially throw an error.
My problem is, I don't want to go through line by line catching each error, I want to catch them all in one statement.
In python you can do this
try:
exampleArray = [1,2,3,4]
print(exampleArray[4])
except Exception as e:
print(e)
pass
What that does is try to print a value from the array that doesn't exist, but it is caught by the except
statement, I am wondering whether something this easy exists in Swift
To clarify, I am not trying to catch an index out of range
error, I just want to catch an error, no matter what it is.
Is it possible without declaring my own errors, and throwing them line by line?