> have a single Exception type at the root of the Exception type hierarchy and make your library only throw sub-types of that. Then you may handle specializations of that, but you need to also handle the root type in case an unknown variant comes along.
Hm, I haven't considered this solution. It works exactly like a #[non-exhaustive] enum. It's a wrapper type that provides type info about specific known variants (subclasses) but also still forces the caller to `catch MyBaseException` (match `_ => {..}`). I may need to update the post. Now it seems that #[non-exhaustive] error handling is equivalent in both cases and the main issue with Java lies in generic code [1]
Hm, I haven't considered this solution. It works exactly like a #[non-exhaustive] enum. It's a wrapper type that provides type info about specific known variants (subclasses) but also still forces the caller to `catch MyBaseException` (match `_ => {..}`). I may need to update the post. Now it seems that #[non-exhaustive] error handling is equivalent in both cases and the main issue with Java lies in generic code [1]
[1] https://home.expurple.me/posts/rust-solves-the-issues-with-e...