While fixing a bug in my project, I catch an interesting behavior of do-catch:
enum KnownError: Error {
case oops
}
enum UnknownError: Error {
case unknown
}
func methodThatThrowUnknownError() throws {
throw UnknownError.unknown
}
do {
print("do start")
try methodThatThrowUnknownError()
print("do finish")
} catch let error as KnownError {
print(error)
}
print("exit")
When we throw an UnknownError
and our do-catch doesn't have a simple catch {...}
in the end (that catch any error) - we will get stuck.
The print("exit")
will never call.
I catch this behavior in Xcode 13.3, project with iOS 15.0.
Also, I tried to run this code via CLI and got:
I think, Xcode should show a live issue about missing common catch {...}
block.
So, what do you think?