I know that Swift does not have try/catch, but are there any other methods by which I can exit from a function to one higher up on the stack without returning to the intervening functions? For example, in the following code is it possible to exit from d()
directly back to a()
so that only the first print statement (in a()
) is executed?
func a() {
b()
println("returned to a()")
}
func b() {
c()
println("returned to b()")
}
func c() {
d()
println("returned to d()")
}
func d() {
// exit to a()
}
a()
If Swift did have try/catch I could simply wrap the call to b()
with try
and throw an exception in d()
.