News for hackers. Stuff that matters.
Re:Why Go's Error Handling Is Awesome by mabbo on Tuesday July 07, 2020 @09:35AM (#23759077)
> Unchecked exception based error handling, of course, is irretrievably broken.

The mental model I have with Java unchecked exceptions it that all methods, by default, have "throws UncheckedException" at the end of it. And since the calling line of code is also a method, it doesn't need to explicitly handle it.

What would be nice is a means to mark a method as "Cannot throw exceptions of any kind", removing the unspoken "throws UncheckedException" from the signature and forcing that method to internally handle all unchecked exceptions- enforced by the compiler.

Perhaps with the coming pattern matching to Java, we'll be able to resolve this with Return value wrapping types that are One-Of (return value type, Exception type 1, Exception type 2, etc...). Then you could call the method, and pattern match the result by type.

There are no comments on this comment yet.