Hi, everyone.
I'm confused about error handing in Rust.
For example:
I have two function. The first may end up with IO error or parse error. The second may end up with a parse error and out of bound one.
Now I know the way to handle this situation. I should create my own Error type.
For first function:
enum FirstFuncErrorType {
IoErr,
ParseErr,
}
For second function:
enum SecondFuncErrorType {
ParseErr,
OutOfBoundErr,
}
or a union enum of both
enum FirstFuncErrorType {
IoErr,
ParseErr,
OutOfBoundErr,
}
Is there a more convenient way in such situation.
In java I can add and remove exception types that a function throws. There is no need for special error type for each function or a super huge one for all cases in my crate.
void firstFunction() IOException, ParseException{
//...
}
void secondFunction() ParseException, OutOfBoundException{
//...
}
I know about good programming style and etc. I'm just curious about the possibility.
Thanks for any help.