I'm going through the ziglings exercises and was surprised by this behaviour:
My code:
`fn fixTooSmall(n: u32) MyNumberError!u32 {
// Oh dear, this is missing a lot! But don't worry, it's nearly
// identical to fixTooBig() above.
//
// If we get a TooSmall error, we should return 10.
// If we get any other error, we should return that error.
// Otherwise, we return the u32 number.
return detectProblems(n) catch |err| {
if (err == MyNumberError.TooSmall) {
return 10;
} else if (err == MyNumberError.TooBig) {
return err;
}
};
}
fn detectProblems(n: u32) MyNumberError!u32 {
if (n < 10) return MyNumberError.TooSmall;
if (n > 20) return MyNumberError.TooBig;
return n;
}
`
I thought since I covered the two possibilities for the err value (on the right side of catch) then either the 10 or the TooBig would be returned. I get the following compiler error:
error: 1 compilation errors exercises/024_errors4.zig:62:42: error: expected type 'error{TooBig,TooSmall}!u32', found 'void' return detectProblems(n) catch |err| { ^ exercises/024_errors4.zig:55:37: note: function return type declared here fn fixTooSmall(n: u32) MyNumberError!u32 {