I would need confirmation that this pattern of nested throw is not correct when using do try. In fact, when I catch a thrown error, I want in some cases to throw a new exception.
These patterns seem to the cause of some problems (now corrected).
do {
let result = try someFunction
} catch someError {
throw someException // A new one
} catch {
// generic actions
}Or with nested do
do {
let firstResult = try someFirstFunction
do { // A nested do pattern
let result = try someFunction
} catch someError {
throw someFirstException // A new one
} catch {
// generic actions
}
} catch someFirstException {
} catch {
// generic actions
}
}Am I right assuming that in such a pattern, someException may be trapped either at line 6 or 10 ?
Yes, it's clear. No, it won't be caught on line 5.
You can think of this as the 2nd throw jumping out of the try-catch construct. You can also regard the original throw as having been caught already. Or, you can think of the catch blocks catching only throws inside the "do" scope.
Note that there's no real point for it to work the way you suggest, because you already know what kind of error it is, so there's no need to re-analyze it. Further, if it was a kind of "re-catch", any errors thrown inside the final default catch block would produce an infinite recursion.