3 ms·
I don't know Rust, but I really liked Boost.System's approach[1], which was included in C++11, and have used that scheme in other languages. The point there is
by magicalhippo 1y ago
I don't know Rust, but I really liked Boost.System's approach[1], which was included in C++11, and have used that scheme in other languages.
The point there is the error is not just an error in isolation, but it has an attached error category as well. And the error categories can compare errors from other categories for equivalence.
So for example, say you have an error which contains (status_404, http_result_category), then you can compare that instance with (no_such_file_or_directory, generic_category), and because http_result_category knows about generic_category, it can handle the comparison and say that these are equivalent[2].
This allows you to preserve the quite detailed errors while also using them to handle generic error conditions further up.
That said, doing this for every function... sounds tedious, so perhaps not worth it.
[1]: https://www.boost.org/doc/libs/1_88_0/libs/system/doc/html/system.html https://www.boost.org/doc/libs/1_88_0/libs/system/doc/html/s...
[2]: https://www.boost.org/doc/libs/1_88_0/libs/system/doc/html/system.html#usage_testing_for_specific_error_conditions https://www.boost.org/doc/libs/1_88_0/libs/system/doc/html/s...