Many languages have try.. catch.. finally.. method to catch errors and it is a good general method for picking up errors. What is Rust's general error catching method?
I checked the net and found a number of error catching methods in Rust. For example, use of ? and .expect() and returning Result etc. What general method in Rust can be applied to most situations? Thanks for your insight.
Rust uses Result<T, E> for error handling, and the ? operator for unwrapping the data or propagating the error to the caller. There's a lot more to say about it, but the details are not entirely interesting until you have a need to get into them.
The major concern is that Result is what you want and there is no exception handling facility [1] in the language.
So the error type of the Result needs to implement Into<T> where T is the type of the error produced by the expression.
So you can't use String directly since there isn't an impl Into<String> for std::io::Error[1], but you can create an error type that works the same way pretty easily
One thing that nobody mentioned explicitly is that there's no equivalent of finally built into error handling, because Rust doesn't need it. Destructors run even when an error makes ? return early, so automated resource cleanup works just fine.