enum Exception: Error {
case case1, case2
}
//только метод с ключевым словом "throws"
//может выбросить ошибку
func methodWithException1() throws {
throw Exception.case1
}
//В версии 6:
//можно указывать типы ошибок
func methodWithException2() throws(Exception) {
throw Exception.case2
}
do {
try methodWithException1()
}
catch let e as Exception {
print("Error happened: \(e)")
}
catch {}
//В версии 6:
do {
try methodWithException2()
}
catch let e {
print("Error happened: \(e)")
}