Live data from Hacker News

Unchecked Java: Say goodbye to checked exceptions

github.com

21–30 of 297 posts

Re: Unchecked Java: Say goodbye to checked exceptions

#21
post #16

Still hoping that Java will support such a choice (compiler option) out of the box in the future. Also, without IDE support such a plugin will never gain a lot of traction.

Manifold provides this feature and supports IntelliJ IDEA and Android Studio.

https://github.com/manifold-systems/manifold/tree/master/man...

Re: Unchecked Java: Say goodbye to checked exceptions

#22
post #7

Allowing unchecked exceptions in languages without explicit error handling or the return of error values is a mistake IMO! Makes it impossible to call a function safely

I would argue the opposite: Junior and senior developers alike catch and swallow or log checked exceptions all over the place, making it impossible to know if your method call was successful or not.

Re: Unchecked Java: Say goodbye to checked exceptions

#24
post #20

Exception based error handling is so bad and unsafe that adopting functional error handling with Either, Try etc as implemented by functional addon libraries for many languages, while not yet common, in time it will become the new default even in OO languages. (just like it's been the default in functional languages for decades) Functional error handling types are much simpler, safer and more powerful. Simpler becaus…

Exception based error handling is unsafe when they are unchecked exceptions. Checked exceptions however are as safe as Either, Try, Monads, Applicatives or whatever. You are forced to declare them in your method signature, the caller is forced to either handle them or rethrow them + declare them as well. And I guess this is precisely why so many developers hate them; they don't like the extra work they have to do to catch all those edge conditions. This is why we see so many empty catch blocks or upcasting to Exception or even Throwable; it is laziness.

I would also argue that checked exceptions are no more complex than Eithers, Try or Applicatives. Actually passing Eithers or Applicatives around everywhere can easily clutter your code as well, IMO it can be worse than checked Exceptions.

Re: Unchecked Java: Say goodbye to checked exceptions

#25
post #21
post #16

Still hoping that Java will support such a choice (compiler option) out of the box in the future. Also, without IDE support such a plugin will never gain a lot of traction.

Manifold provides this feature and supports IntelliJ IDEA and Android Studio. https://github.com/manifold-systems/manifold/tree/master/man...

I am using Eclipse. But will definitely keep this in mind, should I every switch to IntelliJ.

Re: Unchecked Java: Say goodbye to checked exceptions

#26

This seems like a major improvement for Java readability as shown by the examples. What I don't like is the examples of having to use Maven or Gradle to install it. Why does that have to be so verbose, and something written in another language?

Ha, yeh. At first I had the command line examples first, but everyone was going on and on about maven and stuff, so I figured that's what the audience wants.

[EDIT] I moved the command line stuff back to the top of the README. XML makes my eyes bleed too...

Re: Unchecked Java: Say goodbye to checked exceptions

#27
post #20

Exception based error handling is so bad and unsafe that adopting functional error handling with Either, Try etc as implemented by functional addon libraries for many languages, while not yet common, in time it will become the new default even in OO languages. (just like it's been the default in functional languages for decades) Functional error handling types are much simpler, safer and more powerful. Simpler becaus…

Exception based error handling is unsafe when they are unchecked exceptions. Checked exceptions however are as safe as Either, Try, Monads, Applicatives or whatever. You are forced to declare them in your method signature, the caller is forced to either handle them or rethrow them + declare them as well. And I guess this is precisely why so many developers hate them; they don't like the extra work they have to do to…

Ultimately, core language features that make things ergonomic enough for lazy developers to get it right will result in better software.

And ones that are so unergonomic that only industrious developers will get them right will result in worse software.

Modern languages allow these to be zero cost abstractions so there is little tradeoff.

Re: Unchecked Java: Say goodbye to checked exceptions

#28
post #20

Exception based error handling is so bad and unsafe that adopting functional error handling with Either, Try etc as implemented by functional addon libraries for many languages, while not yet common, in time it will become the new default even in OO languages. (just like it's been the default in functional languages for decades) Functional error handling types are much simpler, safer and more powerful. Simpler becaus…

Checked exceptions are exactly analogous of Result/Either types. They are just built into the language with syntactic sugar, automatically unwrap by default (the most common operation), can be handled on as narrow or wide scope as needed (try-catch blocks), does the correct thing by default (bubbling up), and stores stack traces!

In my book, if anything, they are much much better! Unfortunately they don’t have a flawless implementation, but hopefully languages with first-class effects will change that.

Re: Unchecked Java: Say goodbye to checked exceptions

#29
post #20

Exception based error handling is so bad and unsafe that adopting functional error handling with Either, Try etc as implemented by functional addon libraries for many languages, while not yet common, in time it will become the new default even in OO languages. (just like it's been the default in functional languages for decades) Functional error handling types are much simpler, safer and more powerful. Simpler becaus…

> Safer because unlike exceptions, they force callers to handle all potential outcomes, but no more.

Which is bad. In 99% of cases I have no specific error handling for the given problem. Just let the process crash or be handled by application server / framework.

Representing these kinds of error conditions in the code which I have no interest in handling is just noise.

Re: Unchecked Java: Say goodbye to checked exceptions

#30
post #14
post #7

Allowing unchecked exceptions in languages without explicit error handling or the return of error values is a mistake IMO! Makes it impossible to call a function safely

Exactly, C++ exceptions are horrible, you never know what throws what. Java made C++ exceptions better by making them explicit, so you always know what throws. Then Kotlin came and made everything a unusable mess (don't get me wrong, I love Kotlin, just hate that it doesn't have explicit exceptions). I honestly think the best error handling strategy is employed by Zig, then Rust. they're very explicit while not getti…

It is true that C++ exceptions are not checked and are rarely part of the interface signature but C++ exceptions are not a tool for general error handling in the context you're comparing them against Java, Zig and Rust. Java uses exceptions for control flow while C++ doesn't. Zig and Rust don't have exceptions at all. What Zig and Rust have as error handling mechanisms C++ has them too. C++ exceptions are of a literal meaning - exceptional cases which you don't expect to happen and you usually don't know how to recover from. In this case propagating the exception up to the thread entry point and doing whatever in that case (logging, terminating, restarting, etc.) is vastly better than language forcing me to check for each possible exception all the way through the whole function callstack - it's useless.
Post reply on HN