News for hackers. Stuff that matters.
Re:Why Checked Exceptions Failed by newaccount74 on Saturday July 15, 2023 @02:11PM (#36739512)
It's a very common pattern, almost every modern language has a "map" function. The map function can throw a superset of the exceptions that its argument can throw. If checked exceptions can't deal with this, they'll be of limited use.
Re:Why Checked Exceptions Failed by interlocutor on Saturday July 15, 2023 @02:58PM (#36739871)
In the case of map function hopefully you're using it with methods that don't fail in serious ways, and don't need strong error recovery. If so Java has RuntimeException to handle that case. If serious errors are possible and strong error recovery is needed, then you need to avoid the conveniences offered by functional style programming.
Re:Why Checked Exceptions Failed by Quekid5 on Saturday July 15, 2023 @03:13PM (#36740006)
The problem is that if some code you call throws a checked exception (InterruptedException being an extremely common culprit) then you must wrap... and suddently nobody calling YOUR code can catch that InterruptedException reliably because it's now a SomeException (doesn't even have to be RuntimeException specifically) with an added "suppressed" exception that you now have to check for.

... so the basic "catch" syntax starts to fall apart because now you have to catch everything and resort to stuff like Guava's Throwables helpers.

It's madness.

The problem ultimately is variance: Methods are covariant, but throws clauses must be contravariant.

There are ways to solve this but "checked exceptions" (as in Java) are not the right way. Ask anyone who's worked in Scala on the JVM which they prefer and you'll have your answer.

Re:Why Checked Exceptions Failed by dasyatidprime on Saturday July 15, 2023 @03:48PM (#36740311)
It's possible to use a type parameter in a throws clause in Java, last I checked (as I also mentioned in more detail above). But it doesn't seem to be common practice, so interop is still a disaster.
Re:Why Checked Exceptions Failed by Quekid5 on Saturday July 15, 2023 @10:00PM (#36742795)
That only works up to one checked exception type, because Java doesn't have anonymous union types.

It really is a lose-lose unless Java grows a more powerful system around this.

Re:Why Checked Exceptions Failed by crabbone on Sunday July 16, 2023 @04:43AM (#36744849)
Sorry. This is nonsense. map() is the bread and butter of any program. Besides, you cannot ever decide whether an exception is important or not -- it's always in the purview of the user.

Re-throwing a non-checked exception is what I described as the usual / typical coping mechanism in languages with checked exceptions. Which is obviously a way to negate the whole feature.

Re:Why Checked Exceptions Failed by breadwinner on Sunday July 16, 2023 @09:42AM (#36746890)
Sorry, disagree. map() didn't even exist in Java until recently. It is convenience at the cost of some safety. If you're writing a non-critical or throw away code you may not care about strong guarantees. Personally I prefer strong guarantees over convenience. I would only use map() for things that can't throw checked exceptions. A for loop isn't that hard to write.
Re:Why Checked Exceptions Failed by bsder on Saturday July 15, 2023 @06:33PM (#36741545)
> The map function can throw a superset of the exceptions that its argument can throw.

Wait. Why should a map care about what exceptions it's arguments can throw?

A map is storing a thingit. A thingit should exist independently before it gets placed into a map. Placing a thingit into a map should not invoke anything on the thingit. The only exceptions coming back from attempting to place a thingit into a map should be exceptions caused by the map.

What am I missing?

Obviously, there are maps that conflate themselves and do things like take ownership when an object is placed into the map. But that's not the general case and presumably you wrote the map specifically with that in mind.

Re:Why Checked Exceptions Failed by hollerith on Saturday July 15, 2023 @06:40PM (#36741581)
You're thinking of a finite map, also called a hash table or a dictionary.

The map function takes a function and a list and applies the function to every element of the list:

  map double [1,2,3] = [2,4,6]
Re:Why Checked Exceptions Failed by bsder on Saturday July 15, 2023 @11:38PM (#36743342)
Whoops. Yeah, I wasn't thinking about map, fold, accumulate, etc. Thanks for the correction.