Things I Enjoy in Rust: Error Handling
It&#x27;s interesting to see modern languages tackling checked error handling. Particularly in the light that Java&#x27;s checked exceptions are widely considered to have been a failure. Yet I wonder if Java had better support for things like union types etc. if it would have turned out differently. After all, it did offer at least potential to achieve what everyone is after: you can write a piece of code and know for sure that you handled every possible type of error.<p>The most painful aspect of Java&#x27;s (original) exceptions was how the only mechanism to handle multiple errors as a single case was using inheritance in the exception hierarchy. The result was that they propagated through interfaces and broke downstream code and it became pretty much impossible to design and maintain a stable API without wrapping exceptions excessively which in turn destroys the utility of the exception hierarchy, making the whole exercise futile.<p>The article seems a little superficial though. Immediately exiting with &#x27;panic&#x27; does not seem like a real error handling approach for any realistic application. It doesn&#x27;t show how you could handle different types of errors (eg: file not found vs I&#x2F;O error reading file) with different cases. The case it does present is easily handled elegantly by nearly any error handling design.