enum Exception: Error {
case case1, case2
}
//only the method with the keyword "throws"
//can throw an error
func methodWithException1() throws {
throw Exception.case1
}
//In version 6:
//You can specify error types
func methodWithException2() throws(Exception) {
throw Exception.case2
}
do {
try methodWithException1()
}
catch let e as Exception {
print("Error happened: \(e)")
}
catch {}
//In version 6:
do {
try methodWithException2()
}
catch let e {
print("Error happened: \(e)")
}