Live data from Hacker News

You’re better off using Exceptions

eiriktsarpalis.wordpress.com

241–242 of 242 posts

Re: You’re better off using Exceptions

#241
post #44

Earlier quoted context omitted.

Actually, I’d argue that exception (that are caught) should only be used for recoverable errors. If you can’t recover, then you should crash.

The great thing about exceptions is that they implement both of these behaviors with a single mechanism. For recoverable errors, you catch. For unrecoverable ones, you don't. The exception throwing mechanism unwinds the entire stack and crashes the app with a helpful stack trace.

True!

Re: You’re better off using Exceptions

#242

Earlier quoted context omitted.

I haven't written very much Java, but here are some differences between Java checked exceptions and Rust errors as I understand them: In Java, a function may throw a long list of checked exceptions, and these lists tend to grow to inconvenient sizes in larger programs. For example, if foo() calls bar() and baz(), which each throw 3 different exception types, then now foo() might throw 6 different exception types. In…

I don't think this is a real difference. You can make the exact same API design mistakes regardless of which error delivery mechanism you use. The important thing is for the API designer to think about the abstractions, i.e which types of errors should be part of the API and which errors are just implementation details that may change. If the API designer is too lazy to put enough thought into that then the result wi…

I do not know much about java, but I think that the part about automatic conversion on passing errors is not available in java.
Post reply on HN