Catch clauses in Swift must be exhaustive. Does it mean I always need to use a wildcard or empty catch clauses whenever I want to avoid error propagation? Example:
enum Oops: Error {
case oh, ouch, meh
}
func troublemaker() {
do { throw Oops.meh }
catch Oops.oh {}
catch Oops.ouch {}
catch Oops.meh {}
// Error: Error is not handled because the enclosing catch is not exhaustive
}
Of course, it is fixed if I add throws
to the function. Same goes for adding either catch {}
or catch _ {}
.
But is there any way to make exhaustive catch blocks other way? Like, perhaps defining the allowed type of the error to throw, so my enum Error would make it exhaustive?