News for hackers. Stuff that matters.
Re:Why Checked Exceptions Failed by breadwinner on Saturday July 15, 2023 @09:06AM (#36736326)
I have extensive experience in C# as well as Java. It is bizarre to suggest that checked exceptions have failed. It is unchecked exceptions that have failed. It is the biggest flaw of C#, in fact. Why?

As an example, I wrote some very good C# code, carefully tested it, made it work flawlessly, then suddenly it started crashing. What happened? Someone made a change in a function I was calling, and it started throwing a new exception. This would have caused a compile error in Java, not a crash.

The list of recoverable exceptions that can be thrown by a method should be part of the contract. It should be written down by the programmer, and enforced by the compiler. If not, then to avoid crashing you would have to catch the root Exception class, which everyone agrees is a bad idea.

More on checked vs unchecked exceptions here: https://forum.dlang.org/thread/[email protected]...

Re:Why Checked Exceptions Failed by EMM_386 on Saturday July 15, 2023 @09:17AM (#36736439)
> Someone made a change in a function I was calling, and it started throwing a new exception.

If it has nothing to do with your code, why not either let it bubble up the stack or try/finally it to do whatever clean-up you need to do before re-throwing it and letting it move on to a global logger or similar.

If it is something you care about you can always catch the specific exception type and handle it.

Maybe whoever worked on the other function wasn't even aware it might throw that particular exception.

Granted I am far more experienced in C# than Java, but the idea that with every code change you potentially have to review and declare every single type of exception seems like madness ("what happens if we pull the cord when it's here, what type will that throw?").

Re:Why Checked Exceptions Failed by breadwinner on Saturday July 15, 2023 @09:45AM (#36736693)
Imagine that the functionality implemented by your method is very important. This functionality should not be needlessly aborted. If so you want to be aware of errors you can recover from, correct? This is why checked exceptions are helpful. It gives you a guaranteed-by-compiler list of exceptions and you can decide which of those you should recover from.
Re:Why Checked Exceptions Failed by wiseowise on Saturday July 15, 2023 @10:45AM (#36737257)
Yes. But it’s not as simple as checked=good, unchecked=bad and vice versa.
Re:Why Checked Exceptions Failed by throwanem on Saturday July 15, 2023 @12:22PM (#36738323)
Or I can catch any exception out of the codepath I'm concerned about, examine it to see if it's one of the known set of exceptions I intend to handle, and then either do so or rethrow it.

If there's a benefit to compile-time exception checking over this method, I have to admit I don't see it. But I've also never worked deeply enough with Java to be familiar with the nuances of its exception handling, so that may be why.

Re:Why Checked Exceptions Failed by joexner on Saturday July 15, 2023 @01:49PM (#36739322)
Checked exceptions give you, essentially, syntactic sugar for handling just a few kinds of exceptions and re-throwing the rest.

It's useful when there are one or two error cases you want to retry or handle specially, but you want to just barf any other error up the stack. It's a specific use case but it's prevalent.

The downside is that sugar can only separate your error conditions by Java type. If everything is just an Exception, you'll have to use sort out your error cases in code.

Re:Why Checked Exceptions Failed by throwanem on Saturday July 15, 2023 @01:54PM (#36739370)
By the sound of it, that's more like syntactic salt, or maybe syntactic thallium - `else { throw error; }` seems much simpler by comparison.

Being able to know what exceptions can possibly be thrown at a given point is useful, but seems like a problem better solved through static analysis than by requiring annotations.

Re:Why Checked Exceptions Failed by newaccount74 on Saturday July 15, 2023 @02:23PM (#36739595)
The problem is that handling arbitrary errors can be very complex. It's easy to make errors in the error handling code. Especially if the error you are handling never occurs -- because there's no way to test error handling code for an error that never happens.

That's why it is really useful to know when a call can fail, and what kinds of errors you have to expect.

If you always have to add a generic error handler for possible unknown errors, then you'll write a lot of untested, dead code.

Re:Why Checked Exceptions Failed by throwanem on Saturday July 15, 2023 @07:55PM (#36742032)
> Especially if the error you are handling never occurs -- because there's no way to test error handling code for an error that never happens.

Sure there is. Find the way it happens, do that, and test that the handler does what it's supposed to. Or, if you can't do that, mock the error.

I suppose that's not guaranteed to be straightforward in Java; it's been a long time but I seem to recall libraries being provided in compiled form, without sources, and it therefore not always being possible to identify the conditions that need to be set up in a unit test. If I recall that correctly, it makes me very glad I no longer use the language.

> If you always have to add a generic error handler for possible unknown errors, then you'll write a lot of untested, dead code.

The generic handler in this case is

    else {
      throw error; // rethrow
    }
You're not wrong that there's value in knowing what exceptions can be thrown at a given point in code. But, as I mentioned in another comment, that's something that can in the general case be known through static analysis, and should. In fact, the Java compiler must already be doing something substantially similar to that analysis for checked exceptions to work at all! Looking for throw statements rather than "throws" declarations seems like it shouldn't be that much more difficult, and I think the burden on Java developers could be substantially lightened thereby in that "throws" declarations would no longer be required.
Re:Why Checked Exceptions Failed by Akronymus on Saturday July 15, 2023 @02:43PM (#36739742)
This is one of the main reasons why I personally try to avoid exceptions and instead encode failure into the type system. For example, returning a Result<'t,string> rather than just a 't. (You can refine the type further). Altough, in most languages that approach results in a lot of boilerplate.

In F# it works quite well, though.

Re:Why Checked Exceptions Failed by necovek on Saturday July 15, 2023 @03:02PM (#36739911)
How is this different in practice? Checked exceptions are simply "syntactic sugar" for error types (exception objects with a few special handlers to return them and receive them).

You can write almost exactly the same code with your Result by ignoring the error until the point you would catch it with exceptions.

The only difference is that exceptions bubble up if unhandled, which requires a generic catch to match code ignoring errors otherwise.

Re:Why Checked Exceptions Failed by Akronymus on Saturday July 15, 2023 @05:53PM (#36741298)
> How is this different in practice?

It is quite a bit more explicit in that something can have an error and in what ways it can error (if you enrich the type in that way), while still being ergonomical. And it reserves exceptions for the truly unexpected/exceptional cases.

Re:Why Checked Exceptions Failed by necovek on Saturday July 15, 2023 @09:37PM (#36742678)
Are we comparing the same things? Adding exceptions to the method signature is pretty explicit to me too.

It's also pretty ergonomical depending on how you generally treat errors you don't care about.

I do find your point about exceptions being for unexpected things interesting: basically, split errors into two classes and use separate mechanisms for each.

I generally feel that this differentiation would never hold between different codebases (an HTTP library may consider network error something "normal", but users of that library might consider it exceptional), but it's surely an interesting concept.

I also think that we as developers are pretty bad at handling both expected and unexpected errors, so having two mechanisms will only make us less likely to do so (not by much, though).

FWIW, my take is that they are largely equivalent except for more or less syntactic support for the approach.

Re:Why Checked Exceptions Failed by Akronymus on Saturday July 15, 2023 @10:32PM (#36742951)
> FWIW, my take is that they are largely equivalent except for more or less syntactic support for the approach.

Yeah, as with lambda calculus and turing machines, they are equivalent in capacity.

> Are we comparing the same things? Adding exceptions to the method signature is pretty explicit to me too.

Maybe, maybe not. IME the IDE support for exceptions is quite a bit worse than for returning results and such.

> I do find your point about exceptions being for unexpected things interesting: basically, split errors into two classes and use separate mechanisms for each.

> I generally feel that this differentiation would never hold between different codebases (an HTTP library may consider network error something "normal", but users of that library might consider it exceptional), but it's surely an interesting concept.

Isn't the two ways to handle it already a thing with checked and unchecked exceptions, though? As in having wrappers that convert one to the other.

> I also think that we as developers are pretty bad at handling both expected and unexpected errors, so having two mechanisms will only make us less likely to do so (not by much, though).

I don't quite agree with that, as with encoding it in the type system conveys more intentionality than with exceptions, IMO.

Re:Why Checked Exceptions Failed by necovek on Sunday July 16, 2023 @02:44AM (#36744276)
> I don't quite agree with that, as with encoding it in the type system conveys more intentionality than with exceptions, IMO.

Sure, but why keep using exceptions then at all? I am fine with returning errors making them explicit, but I would avoid exceptions everywhere (Go-style).

Re:Why Checked Exceptions Failed by Akronymus on Sunday July 16, 2023 @08:09AM (#36746084)
Because of interop necessity, mostly (As with f# which has exceptions because .net and c#).
Re:Why Checked Exceptions Failed by Kwpolska on Saturday July 15, 2023 @09:30AM (#36736567)
> The list of recoverable exceptions that can be thrown by a method should be part of the contract.

If it’s really recoverable, then should it actually be an exception? How often do you see exceptions that are recoverable?

> If not, then to avoid crashing you would have to catch the root Exception class, which everyone agrees is a bad idea.

I disagree that it’s a bad idea, having a catch-all exception handler to avoid crashing the entire app is a good idea.

Java also has RuntimeException, and with it, a whole host of exceptions that may occur but are not declared. Should every function that uses the division operator be marked with `throws ArithmeticException` since it may end up being a division by zero? That would quickly become absurd.

Re:Why Checked Exceptions Failed by kaba0 on Saturday July 15, 2023 @09:47AM (#36736711)
Yes, in Java’s parlance an Exception is a recoverable code path, Error is the kind that is not.

E.g. a network call failing due to some IOException can be easily retried, that’s a proper error handling.

Re:Why Checked Exceptions Failed by ahtihn on Saturday July 15, 2023 @03:09PM (#36739969)
How are you supposed to recover from IllegalArgumentException or NullPointerException?
Re:Why Checked Exceptions Failed by kaba0 on Saturday July 15, 2023 @05:33PM (#36741155)
Recoverable, as a technical term. You can catch an NPE and follow it with any kind of code you wish, it will be correctly “handled” by the VM. (The semantics of course depend on the exact specifics, but returning a server 500 error and not failing the process for example in a web server is completely valid).

You can try catching an OutOfMemory Error, but it is not guaranteed that your handling code can successfully run. Hence, non-recoverable.

Re:Why Checked Exceptions Failed by chongli on Saturday July 15, 2023 @11:56AM (#36738013)
If it’s really recoverable, then should it actually be an exception?

That's the problem with exceptions in general. They're a hammer that makes everything look like a nail. People start using them for all kinds of control flow situations because they're more convenient than having to deal with a lack of type system support for optional values, etc.

You get to the point where you have a parser that is expecting a digit and it encounters an alphabetic character so it throws an exception!

Re:Why Checked Exceptions Failed by saurik on Saturday July 15, 2023 @12:59PM (#36738795)
There are remarkably few situations involving recoverable errors, though, and they almost all look like "not found"--which includes your parse integer example--and, even then, most of the time you will want a forceful automatic exception variant and not a "recoverable" error value as there is almost never anything to do instead: try-parse is so rare of a thing that is correct to do it warrants having a quick "try" attached to the expression.

In contrast, there are a billion ways in which almost every line of code can fail--even stuff people are super sure could never fail is still usually at least subject to stack exhaustion--and almost none of these failures are things you should locally "handle"; and yet in many--even most--cases these are situations you can still recover from at a higher level if you don't screw up your own logic (which is not the point of these errors).

Re:Why Checked Exceptions Failed by Akronymus on Saturday July 15, 2023 @02:59PM (#36739882)
A parser failing is something I'd expect to be recoverable. And I'd expect it to return where it failed and why. You can do that without throwing exceptions at all, and instead encode it in the type. Like returning a result<parsedObject,failureReason>. (Can be further refined, like adding the already parsed/yet to be parsed string to the failurereason as a value) I WANT to be forced to handle it right there and then rather than potentially forgetting a try catch, or checking the boolean returned if it was successful or checking the out parameter if it is not null (boolean tryparse(out parsedObject) is something I see commonly)

For me it is much more ergonomic to use a

  match tryparse somestring with
  | Ok obj -> proceedFurther obj
  | Error reasons -> handleerror reasons
For truly exceptional cases you don't expect to be recoverable? Yeah, throw an exception.
Re:Why Checked Exceptions Failed by arzig on Saturday July 15, 2023 @09:12PM (#36742513)
It may not be recoverable locally, but the caller may know how.

Consider Files.createFile. It throws if the target already exists. That method has no way of knowing what the recovery is, however, the caller might.

It could be that the caller wants to explode, but maybe its part of some kind of singleton launch where the recovery is to pass some piece of data off to whoever created the file originally.

Maybe this is a bad example since there’s not much interesting in the return of Files. But it’s exceptional in that it’s an abort rather than a success.

That said, checked exceptions are still trash because they don’t work across thread boundaries or with futures. ExecutionException is the catch all baked into the design because they needed something. The idea could have been good though because naming error handling visible is useful. Java just has the misfortune of designing early before the kinks had been worked out and now we get nice stuff like Rust has.

Re:Why Checked Exceptions Failed by scarface_74 on Saturday July 15, 2023 @09:12AM (#36736375)
Catching the root exception is not a bad idea. If you had caught the new exception what would you have done with it?

Most of the time, it’s either catch the exception, log it in a central logging system keep moving and have a central alerting system or catch the exception log it and crash the program.

Re:Why Checked Exceptions Failed by simias on Saturday July 15, 2023 @09:26AM (#36736524)
> Catching the root exception is not a bad idea. If you had caught the new exception what would you have done with it?

Something relevant to the error condition, probably?

There may be some cases where the total set of possible errors is too large to meaningfully handle every one of them specifically (for instance if you call a high level GPU initialization routine that can fail in a myriad of ways) but that's not true in all cases. Maybe the new error was in fact recoverable, or maybe it calls for some more specific diagnostics.

At any rate I completely agree with the parent that changing the set throwable exceptions should be considered a breaking API change and should be enforced by the compiler. If an API method wants to future-proof and be able to throw anything, it can declare just that and everybody will know to expect the unexpected.

That's why I vastly prefer Rust's Result<> system which does most of what exceptions do and with fairly similar ergonomics but with normal return values and all the type checking that it involves.

Re:Why Checked Exceptions Failed by scarface_74 on Saturday July 15, 2023 @09:40AM (#36736652)
> Something relevant to the error condition, probably?

And in every language I know you can have catch blocks for specific errors and then have a generic catch all.

Re:Why Checked Exceptions Failed by simias on Saturday July 15, 2023 @11:35AM (#36737745)
The ability to catch exceptions is not the issue, it's knowing what to do once they're caught that's the problem.

The parent apparently had exhaustive exception handling, catching all cases. A new exception is now generated, probably signaling a new error condition, you can't expect the calling code to be able to handle it gracefully.

Hence why a compile error might be a better solution here, the coder could decide whether the new exception can fit an existing handler or requires special handling.

Re:Why Checked Exceptions Failed by saurik on Saturday July 15, 2023 @12:52PM (#36738721)
Realistically speaking, you should essentially never try to "handle" errors with tricky program logic: propagate them up (automatic in languages with exceptions) and eventually--in as few places as possible--report them to the user so the user can decide what to do, not the code.
Re:Why Checked Exceptions Failed by simias on Saturday July 15, 2023 @01:02PM (#36738825)
I disagree, low level exceptions rarely make sense on their on for the users, the automatic propagation of exceptions just promotes laziness by having a catchall "print(exception); exit(1);" at the top level.

If you're lucky you get a proper stack trace that lets you figure out what's going on, but even that is poor ergonomics.

A high level library should report high level exceptions for instance, not minute details of the lower layers. Nothing is more frustrating that having a program fail and all you have is some cryptic "No such file or directory" or "Operation not permitted" error that doesn't tell you what the code was actually trying to do or give you any hint on how to fix it.

Re:Why Checked Exceptions Failed by breadwinner on Saturday July 15, 2023 @09:37AM (#36736621)
It is a bad idea according to Microsoft.

See https://learn.microsoft.com/en-us/dotnet/fundamentals/code-a...

Re:Why Checked Exceptions Failed by scarface_74 on Saturday July 15, 2023 @09:44AM (#36736682)
This is for a library. Whatever the “root” of your code is should have a generic catch all where you do “something”, you don’t want library code (either yours or the system) to decide for the user what should be done with exceptions.

As a library writer, you should do something about exceptions that you can and rethrow the ones you can’t,

Re:Why Checked Exceptions Failed by breadwinner on Saturday July 15, 2023 @09:54AM (#36736775)
> Whatever the “root” of your code is should have a generic catch all where you do “something”

If your only goal is to avoid crashing the app then you can catch the base Exception class at the root of you code and go home. But consider the scenario that you're writing a very important method, where the functionality of your method is very important. If your method does not do its job, the rocket may crash or the patient may die. In this case you want to know what recoverable errors are possible in the functions that your method calls, correct? Wouldn't be it nice to get a guaranteed-by-compiler list of possible, recoverable, errors?

Re:Why Checked Exceptions Failed by scarface_74 on Saturday July 15, 2023 @10:32AM (#36737136)
And then you have a list of catch blocks with the final one being the base.
Re:Why Checked Exceptions Failed by breadwinner on Saturday July 15, 2023 @11:51AM (#36737955)
No. You only catch exceptions you can recover from in your method. Other exceptions should be handled in higher layers.
Re:Why Checked Exceptions Failed by scarface_74 on Saturday July 15, 2023 @12:15PM (#36738234)
I’m talking about the “root” of your app
Re:Why Checked Exceptions Failed by revskill on Saturday July 15, 2023 @09:19AM (#36736458)
Catching at the root is only half of story. You must also have ability to resume where it was thrown.
Re:Why Checked Exceptions Failed by funnymony on Saturday July 15, 2023 @09:27AM (#36736538)
“I wrote some very good C# code“

We all do.. its always that other guy who is at fault :)

Re:Why Checked Exceptions Failed by croes on Saturday July 15, 2023 @09:16AM (#36736416)
>you would have to catch the root Exception class, which everyone agrees is a bad idea.

It's a bad idea to catch an unexpected exception?

Re:Why Checked Exceptions Failed by simias on Saturday July 15, 2023 @09:29AM (#36736562)
The issue brought up by the parent is that the exception needed not be unexpected. If the compiler had generated an error because a new exception type could be thrown by the third party API, the developer could have decided that they either couldn't do anything with it and just add a catchall, or actually implement code specifically to handle this issue.

IMO the entire concept of "unexpected exception" is bogus in and of itself. That's like calling "exit(1)" in your code when something goes wrong instead of using proper error handling facilities.

Admittedly it's very convenient for small scripts where proper error handling might be overkill, but for any serious application it's a massive footgun IMO.

Re:Why Checked Exceptions Failed by tom_ on Saturday July 15, 2023 @10:17AM (#36736989)
You run the risk of swallowing something interesting. This was always the problem with C# exceptions to my mind: there was just one mechanism for reporting errors, which covered everything from the most non-erroneous of events, that aren't even errors, such as file not found or invalid file name encoding or failed to write data to file or socket error during write, to stuff that absolutely should cause the program to go pop and die immediately, such as a null pointer or divide by zero.

Anyway, I sympathize with this thread's OP, as I've had exactly the same problem with C#. In the end, I came to the conclusion you kind of do often have to catch every exception, because you can't trust the functions you call, and the documented exception lists for framework stuff are not always accurate. Safest is to put each call in its own try...catch block, and do any property accesses outside the try...catch block so you find out about the NullReferenceExceptions.

This is annoyingly verbose though.

It also does assume your setters and getters don't throw anything.

I mostly liked C#, but the exceptions aspect is not good. Similarly, I've generally despised working with Go, but the way it deals with errors is not its worst feature! (You do have to pay attention to the linter output though! It's the same err variable every time, so the compiler's fastidious checks for variable use are always foiled...)

Re:Why Checked Exceptions Failed by EricRiese on Saturday July 15, 2023 @10:38AM (#36737194)
> the most non-erroneous of events, that aren't even errors...

You're applying a value judgement that the language makers can't and shouldn't make for you. Whether the error is innocuous or malicious, the happy path of your code cannot proceed and needs explicit handling by the programmer.

Re:Why Checked Exceptions Failed by tom_ on Saturday July 15, 2023 @11:02AM (#36737427)
No value judgement here, I don't think, at least not from me (though of course my values inform every opinion I have, including this one). I simply claim that every path is equivalent, and all must be considered. I claim there is no so-called "happy path" - a term I reject - nor do "errors" really exist.

There is one case where the socket send succeeded, and another where it failed. There is one case where the file name encoding is valid, and another where it is not. And so on. It makes no sense, in my view, for one case to be handled with one language mechanism and the other case to be handled with another.

By comparison, there is (or so I claim!) no valid path where a null pointer is dereferenced, or where a value is divided by zero. So I will accept the requirement for some other mechanism for dealing with these - though by the time the code is released to the wild, I would hope that all such occurrences would have been eliminated.

Re:Why Checked Exceptions Failed by saurik on Saturday July 15, 2023 @01:04PM (#36738847)
The correct behavior for not just the vast majority of these conditions but virtually all of them is the same: propagate the error. You aren't going to sit around and try to "recover" from failing to send a packet or encode a filename: you just report it to higher level code. There might be something you can do at a higher level--such as reconnecting or using a different server from a load balancing list--but at that point the exact reason is irrelevant (and yet should be maintained in case the higher level code needs to inform the user in either a dialog or a log file): failure is, virtually all of the time, boolean in nature and a non-local phenomenon.
Re:Why Checked Exceptions Failed by tom_ on Saturday July 15, 2023 @05:54PM (#36741305)
My opinion was informed by writing the higher levels rather than the lower ones! Yes, the code absolutely is going to try to recover from sending a packet, because it was sending that in service of some larger goal that now needs unwinding partway through. And, yes, it is going to try to reconnect, or use a different server - or whatever.

The thing it really doesn't want to do is punt the issue on to some higher level. Because there isn't one.

But, equally, you don't want to be swallowing interesting problems that genuinely indicate actual bugs. Those, you do want to pass on (and due to the lack of any higher level, your process will be killed, and some mechanism will spring into action to produce a report).

Re:Why Checked Exceptions Failed by beached_whale on Saturday July 15, 2023 @09:25AM (#36736513)
Why not catch System.Exception also? Or just catch
Re:Why Checked Exceptions Failed by breadwinner on Saturday July 15, 2023 @09:30AM (#36736566)
When you catch the root Exception class in C# you end up catching IndexOutOfRangeException as well. You should let the program crash instead because this happened due to a bug in your program. Continuing as if nothing happened is unsafe.

Another issue is that you are not allowing higher layers see the exception, even though they may have logic for recovering from the exception. To see the exception they have to now fix your code by removing the catch-all.

Re:Why Checked Exceptions Failed by Kwpolska on Saturday July 15, 2023 @09:33AM (#36736594)
Catch the root Exception class, show an error, but let the user continue working if possible. For a web app, there already is a catch-all exception handler at the request level that prevents the entire server from crashing. For other environments, having a catch-all handler at some top-level interaction point (i.e. on buttons or menu items) would be a good choice too.
Re:Why Checked Exceptions Failed by breadwinner on Saturday July 15, 2023 @09:41AM (#36736662)
If the exception that was thrown (by a method you called) is in fact a condition your code can recover from, then the functionality of your code was needlessly aborted.
Re:Why Checked Exceptions Failed by wredue on Saturday July 15, 2023 @11:58AM (#36738025)
The “if it’s possible” is a major part of the reason to not catch the root exception.

Catching typed exceptions give you much more easily parsable details about whether or not “it’s possible” to recover.

It’s bad practice to catch the root exception. More often than not, it points to an inexperienced developer

Re:Why Checked Exceptions Failed by beached_whale on Saturday July 15, 2023 @09:32AM (#36736591)
I meant at the higher layers, minus some potential cleaning, a lot of library code is exception neutral and shouldn’t care
Re:Why Checked Exceptions Failed by dbrueck on Saturday July 15, 2023 @09:59AM (#36736816)
I stopped using Java a long time ago, and so I assume the language has gotten better since then, but early on at least it felt like Java almost took pride in making the developer jump through extra hoops. Compared to many other languages, using Java just made me feel tired.

Checked exceptions - a feature that seems to be a cost to the developer 100% of the time while being a benefit far less than 1% of the time - is a quintessential example of Java's tendency to cause developer fatigue.

Re:Why Checked Exceptions Failed by breadwinner on Saturday July 15, 2023 @10:03AM (#36736850)
Some people say the same about strong typing. Like, why do I have to write down the type of every single parameter or variable? Java is making me jump through hoops!

The point is, if you don't need the rigor of a strongly typed compiled language, there are other languages you can use. Perhaps a bash script is all you need.

Re:Why Checked Exceptions Failed by ablob on Saturday July 15, 2023 @10:49AM (#36737290)
In strong typing you don't have to (See type inference). It just means that the shape of the data/object you receive is known to you.

That a lot of languages force you to write it out is not an inherent property of strong typing.

Re:Why Checked Exceptions Failed by wiseowise on Saturday July 15, 2023 @10:49AM (#36737294)
Java is the only mainstream language with checked exceptions and checked exceptions are nowhere near usefulness of static typing.

Following your logic, Java developers can now say “if you don’t like freedom of Java, use Rust/Haskell/Scala to validate everything at compile time”

Re:Why Checked Exceptions Failed by lostmsu on Saturday July 15, 2023 @11:24AM (#36737634)
You could say Rust error handling is more like checked than unchecked exceptions.
Re:Why Checked Exceptions Failed by wiseowise on Saturday July 15, 2023 @11:27AM (#36737672)
It is, that’s the whole point.
Re:Why Checked Exceptions Failed by treis on Saturday July 15, 2023 @11:58AM (#36738030)
Checked exceptions are part and parcel of a type system, though. If you have a foo function that returns a value or error you've got different options. Pseudo code they are:

foo():boolean throws Some, List, Of, Errors

foo():boolean | Some | List | Of | Errors

foo():(boolean | nil) , (nil | Some | List | Of | Errors)

The first is checked exceptions. The second is returning different types. Typically there's some sort of Option wrapper for ergonomics. The third returns a result, err tuple and by checking if err is nil you can see if foo succeeded.

Ultimately they are all the same. What differs is the boilerplate/syntax to accomplish what you want. If what you want is a generic error to handle unknown events then you gotta write it that way no matter which system you use.

Re:Why Checked Exceptions Failed by crabbone on Saturday July 15, 2023 @12:34PM (#36738493)
Java is not the only language that has checked exceptions. C++ has them too, for example, but thanks god virtually nobody uses them in C++.
Re:Why Checked Exceptions Failed by nemetroid on Saturday July 15, 2023 @01:01PM (#36738810)
Checked exceptions (i.e. "dynamic exception specification") were deprecated in C++11 and removed in C++17.
Re:Why Checked Exceptions Failed by gpderetta on Saturday July 15, 2023 @06:33PM (#36741547)
C++ never had checked exceptions. It had dynamic exception specifications but they were a very different (and useless) thing as they were runtime checked not statically.

I wish C++ had checked exceptions.

Re:Why Checked Exceptions Failed by gjvc on Saturday July 15, 2023 @11:58AM (#36738032)
Perhaps a bash script is all you need.

Brutal, even for this site

Re:Why Checked Exceptions Failed by crabbone on Saturday July 15, 2023 @12:32PM (#36738455)
You are very confused... "strong" in strong typing doesn't mean you have to write much or at all. Actually, it doesn't mean anything really. But, let's say, Haskell is probably at least as "strongly typed" as Java -- at least that's how most people understand that wording. And you don't have to write types in Haskell at all. It will be a nightmare (as if Haskell can be anything else, but even by the very low Haskell standards, it would still be a nightmare) code, but it will "work".

Until very recently, Java was just tedious, repetitive, high-entropy language, where you had to write everything multiple times.

Eg.:

    VeryLong<Type> variable = VeryLong<Type>();
In this expression, it's obvious what would be the most likely type of variable, but you still have to write it twice -- which is just worthless use of your time, especially when trying to read this very repetitive mess, and very easy to make a typo.

Recently, Java tried to improve this situation by allowing to omit types when the type inferred by default is the one you want. So, you need to write less. You also need to learn the inference rules, obviously, so it increases the cognitive load and rises expectations towards programmer's skill a bit. But, I think it's fair, since Java from a language for the brain-dead transformed into a language that requires more effort to master. While I'm not sure it's a positive change... this decision by Java developers kind of flies in the face of your argument:

No, it's not necessary to repeatedly spell out what you want your program to do. It's just boring and contributes nothing to the program's correctness. If anything, it only causes the programmer to lose focus and introduces mechanical errors that would've been totally avoidable, had the language was more terse.

Re:Why Checked Exceptions Failed by vips7L on Saturday July 15, 2023 @01:17PM (#36738983)
> Until very recently, Java was just tedious, repetitive, high-entropy language, where you had to write everything multiple times.

More than half a decade ago.

Re:Why Checked Exceptions Failed by esafak on Saturday July 15, 2023 @06:35PM (#36741557)
Which means today's code.
Re:Why Checked Exceptions Failed by breadwinner on Saturday July 15, 2023 @02:42PM (#36739733)
Type inferencing can get you in trouble quickly. Consider this code:

   var fireable = someMethod();
   firable.fire();
The programmer intended this code to fire an employee. Let's say this code is in a military application, and another programmer modified the someMethod() function to return a missile. As long as the missile object has a fire() method this code will compile just fine... and do something the code didn't intend to do.

How likely are you to have employee firing and missile firing in the same program? Not very likely, but the principle is valid, regardless. You need to express your intention more clearly like this:

   Employee fireable = someMethod();
Now if someMethod() is modified to return a missile you get a compilation error, and the world will be a lot safer. You don't want missiles being fired by accident!
Re:Why Checked Exceptions Failed by somehnguy on Saturday July 15, 2023 @04:40PM (#36740736)
This is kind of a ridiculous thing to worry or think about. I’m seeing a lot of type inference in modern Java, and it’s the default way of writing Kotlin.
Re:Why Checked Exceptions Failed by breadwinner on Saturday July 15, 2023 @06:19PM (#36741457)
It is dangerous to call a method on an object whose type is not being checked by the compiler. Whether that's a ridiculous thing to worry about depends on how important your program is. If your work for NASA and your code will run inside the Mars rover, it is not ridiculous to worry about such things, but if you're writing some code that will be used once and thrown away then yeah, it might be ridiculous.
Re:Why Checked Exceptions Failed by somehnguy on Saturday July 15, 2023 @07:16PM (#36741800)
It is being checked by the compiler though. For your example to work both would need to extend a common object (unless the only thing you ever do to that object is call fire(), which is nonsensical) or you would get a compile time error right off the bat.

It's a ridiculous thing to worry about in either of your cases. That incredibly specific situation simply isn't ever going to happen in practice because so many other conditions need to be met for the compiler to let you proceed.

Re:Why Checked Exceptions Failed by breadwinner on Saturday July 15, 2023 @08:40PM (#36742293)
> For your example to work both would need to extend a common object

Not necessarily at all.

> unless the only thing you ever do to that object is call fire(), which is nonsensical

You can be calling other methods on the object in other places, but in one particular block of code you may be only calling fire(). And in that block of code, all the compiler cares is that the type has a fire() method. Thus the compiler is not doing a full check.

> It's a ridiculous thing to worry about in either of your cases.

Not at all... if your program is running inside a NASA rover, or if your program is running inside a robotic surgery machine you have to worry about safety and you want to maximize compile-time checks.

Re:Why Checked Exceptions Failed by ajanuary on Saturday July 15, 2023 @05:40PM (#36741207)
someMethod() could return an implementation of Employee that overloads the fire method to dispatch missiles.

The point being, someMethod is doing some job that you want it to do. It is incredibly unlikely to simultaneously start doing a completely different job, while also returning something of the same shape.

Re:Why Checked Exceptions Failed by breadwinner on Saturday July 15, 2023 @06:01PM (#36741339)
> an implementation of Employee that overloads the fire method to dispatch missiles

If you intentionally break it, that's on you.

> It is incredibly unlikely to simultaneously start doing a completely different job, while also returning something of the same shape.

But it doesn't need to return something of the same shape! The shape is not being checked. All the compiler checks is for the existence of a single method of the same name. You call that type checking?

Re:Why Checked Exceptions Failed by nemetroid on Saturday July 15, 2023 @07:32PM (#36741906)
> > an implementation of Employee that overloads the fire method to dispatch missiles

> If you intentionally break it, that's on you.

The shape is not being checked. All the compiler checks is for the existence of a single class of the same name. You call that type checking?

Re:Why Checked Exceptions Failed by crabbone on Sunday July 16, 2023 @04:29AM (#36744790)
This is a problem of dispatch. Not so much of type inference... The problem with dispatch says that if a method gets overloaded too much and too often, then programmers tend to make mistakes when they assume how the method they call will work.

You should be insane if your program accidentally confuses people with missiles, but I understand that this is a stretch to amplify the point. What tends to happen in practice is that eg. the same method which used to only read something from the local storage gets a new overload that goes out into network, and brings with it a whole new bunch of problems the calling code wasn't prepared to handle. Or, when a string was passed to the method that used to do something simple, and then the method gets overloaded with a more sophisticated method that interprets substrings in the passed string as commands to run some code -- and then you get security problems.

Have you ever seen the IntelliJ interface when it deals with Rust code? I'm not sure if it does the same for other languages with type inference feature. Anyways, the idea here is that the programmer can toggle the display of inferred types to qualify every expression. So, it's really trivial to make sure you aren't calling fire() of a missile instead of an employee. And, in practice, this doesn't lead to problems. This is so because dispatch, essentially, blurs the difference between multiple different objects, while type inference is just a kind of abbreviation. It may cause confusion, but it will be of a different type: the reader might not know what's being abbreviated, whereas with dispatch, the reader may be convinced they know what the author meant, but still be wrong.

Re:Why Checked Exceptions Failed by breadwinner on Sunday July 16, 2023 @09:29AM (#36746777)
> the programmer can toggle the display of inferred types to qualify every expression

That's a terrible solution. Eyeballing is not as reliable as compiler doing a check. The language should provide a way for the programmer to express intent, and the compiler should do the check.

You can express intent more clearly when you say:

    Employee foo = someMethod();
as opposed to:

    var foo = someMethod();
A real-life example: I once helped a kid with her Python program to sort numbers. I looked at the code and the algorithm seemed correctly implemented, but the output was incorrect. The bug turned out to be that she hadn't called int() to convert the user input to integer, so all of the data passed through the entire program as strings, and got sorted as strings. There was nowhere in the code where the programmer could express intent that this is supposed to be integers. This sort of thing would never have happened in Java. Well, unless you misuse 'var'.
Re:Why Checked Exceptions Failed by Akronymus on Saturday July 15, 2023 @02:48PM (#36739776)
F# is strongly typed as well, and I almost never have to write type annotations. Hindley milner type inference is pretty useful. And my IDE of choice also shows the inferred types for easy checking. Altough, without that, it'd be a PITA, as you said about haskell.
Re:Why Checked Exceptions Failed by ok123456 on Saturday July 15, 2023 @12:37PM (#36738531)
If checked exceptions were implemented in such a way that they were inferred, and they weren't erased in the byte code, much like how people use strong types now, they wouldn't be seen as hoops. Meaning, if you didn't explicitly handle a checked exception, it would automatically bubble up yet be visible to your IDE.

I would love if, at design time, all the possible exceptions that could happen were able to be inferred. But, the way it happens in java, it's entirely manual, and it won't catch things where I'm referencing compiled code.

Re:Why Checked Exceptions Failed by LorenPechtel on Saturday July 15, 2023 @04:54PM (#36740858)
Exactly. I have no problem with a function declaring the sort of exceptions it can handle, although simply handling them when they occur is normally good enough.
Re:Why Checked Exceptions Failed by dbrueck on Saturday July 15, 2023 @06:25PM (#36741498)
> The point is, if you don't need the rigor of a strongly typed compiled language

This has nothing to do with strongly typed compiled languages vs alternatives.

Re:Why Checked Exceptions Failed by naasking on Saturday July 15, 2023 @02:10PM (#36739499)
> Checked exceptions - a feature that seems to be a cost to the developer 100% of the time

That's because exceptions are overused for not-truly-exceptional conditions. Languages that throw exceptions when a dictionary does not have a key you're looking for are doing it wrong.

Re:Why Checked Exceptions Failed by narag on Saturday July 15, 2023 @05:09PM (#36740972)
Java almost took pride in making the developer jump through extra hoops

That's exactly it. A holier-than-thou stance, reprised by most comments in this post.

Checked exceptions were a PITA.

Someone has recommended to use another language if you didn't like it. Unfortunately my employer at that time had entered a partnership with Sun that prevented that :)

Another ideological prohibition: no pointers. Well, how do you assign event handlers then? People were extremely confused with anonymous classes. I got the reason instantly.

Re:Why Checked Exceptions Failed by Kamq on Saturday July 15, 2023 @11:17AM (#36737575)
> Someone made a change in a function I was calling, and it started throwing a new exception. This would have caused a compile error in Java, not a crash.

I call BS here. I've worked in a few Java projects, and in every single one, the people changing the method in question would have thrown RuntimeException to stop the compile errors.

If RuntimeException was checked, you might have a point, but given that there's a class of unchecked exceptions, you're relying on discipline instead of the compiler anyways.

Re:Why Checked Exceptions Failed by breadwinner on Saturday July 15, 2023 @11:18AM (#36737589)
You need to help train your coworkers to write better code :) Point this thread out to them.

Seriously, Java doesn't force bad programmers to write good code. It just enables good programmers to write good code.

Re:Why Checked Exceptions Failed by Kamq on Saturday July 15, 2023 @11:31AM (#36737712)
I will acknowledge that this wasn't the best code (or the best programmers).

I will also cede the point that you can write good code in Java.

But my point was that Java wouldn't have enforced the situation to be a compile error, not that you can't write good code in Java. I maintain this point, and I think it's true for the average java project.

If you're getting these benefits from Java, it's the intersection of Java and your team's or your organization's culture, not purely from Java. It's possible for you to gain this benefit and for checked exceptions to have still failed out in the wider world of the average Java project.

Re:Why Checked Exceptions Failed by xen0 on Saturday July 15, 2023 @11:34AM (#36737734)
And a lack of checked exceptions means good programmers can't write good code? So good code may only be written in Java?

No... I don't think so.

Checked Exceptions are at best, just a 'hey, are you sure that's right thing to do here?' and at worst, an additional source of rigidity in your code that blows up the scale of a minor change.

Re:Why Checked Exceptions Failed by breadwinner on Saturday July 15, 2023 @11:53AM (#36737982)
> And a lack of checked exceptions means good programmers can't write good code?

Right, and that was my point at the top post in this thread.

Re:Why Checked Exceptions Failed by xen0 on Saturday July 15, 2023 @01:55PM (#36739374)
Wait, you seriously hold that position!? As in, only Java permits good code?
Re:Why Checked Exceptions Failed by breadwinner on Saturday July 15, 2023 @02:03PM (#36739435)
Each language has its strengths and weaknesses. In the case of exceptions Java gets it right, C# doesn't. There are other aspects that C# does better than Java.
Re:Why Checked Exceptions Failed by anonymoushn on Saturday July 15, 2023 @12:10PM (#36738151)
They also have to throw RuntimeException if they want to use APIs that accept functions and therefor specify which checked exceptions those functions are allowed to throw, like Streams.
Re:Why Checked Exceptions Failed by crabbone on Saturday July 15, 2023 @12:19PM (#36738280)
That is not better code. Couple of try-catch-catch-catch-...-catch cases in a function that would otherwise be 2-3 lines long makes for an awful code.

Also, imagine a situation when an iterator throws an exception. Or you wanted to write f(g()) but now you can't and have to do:

    try:
        T t = g();
    catch E1:
        ...
    catch En:
        ...
    f(t);
Now it takes a much greater effort for the reader to figure out what's going on. It's also tempting to allow some exception cases to succeed so, f(t) is reached even if there was an error. Because these two code pieces are now far apart, it's possible that later edits will introduce bugs because the programmer didn't see that either f(t) is reachable even if g() failed, or accidentally made it reachable when it shouldn't have been.

Bottom line, it makes human errors more likely.

Re:Why Checked Exceptions Failed by mkleczek on Saturday July 15, 2023 @12:28PM (#36738397)
This is only because you use exceptions incorrectly. You can (and should) write:

try {

  final var fResult = f(g());

  //do something with fResult 
}

catch (E1 e) {...}

catch (En e) {...}

That's the main idea of exceptions in all languages: main flow is kept together and exceptional flows are separate.

Re:Why Checked Exceptions Failed by AlphaSite on Saturday July 15, 2023 @12:40PM (#36738575)
I think there’s a strong assumption in this pattern that can and should be handled immediately and that there is a recovery path from the failure, if there is no recovery path and you’re just propagating the error this pattern becomes an awfully verbose return statement.
Re:Why Checked Exceptions Failed by mkleczek on Saturday July 15, 2023 @12:55PM (#36738751)
When structured exception handling was becoming popular (C++ in nineties?) the idea was that immediate error handling (like when you have to check return values for errors) makes the main flow (happy path) blurred and unreadable.

You cannot have both at the same time, I'm afraid.

Re:Why Checked Exceptions Failed by im3w1l on Saturday July 15, 2023 @12:55PM (#36738753)
I think the issue with this pattern is that either we don't care about went wrong, we want to treat all errors the same way, and then having n catch clauses is overkill. Or we do care about went wrong, and in that case the exception type is not enough to identify the issue, as often multiple lines in the try block will throw the same exception type.
Re:Why Checked Exceptions Failed by mkleczek on Saturday July 15, 2023 @01:01PM (#36738808)
Yes - that's one of the issues with structured exception handling. Relying only on exception type itself is not enough as information is lost (ie. the actual source of exception)
Re:Why Checked Exceptions Failed by im3w1l on Saturday July 15, 2023 @01:05PM (#36738857)
Crazy idea: Maybe it would be helpful if we could label operations, and catch by either label or type or (label, type). The we could centralize error handling without losing anything.
Re:Why Checked Exceptions Failed by mkleczek on Saturday July 15, 2023 @01:33PM (#36739161)
While deceptive at first... Just try to imagine how "extract method" refactoring would work...
Re:Why Checked Exceptions Failed by im3w1l on Saturday July 15, 2023 @02:22PM (#36739587)
It would have to do some clever rewriting of the logic or it could simply declare that extracting method isn't available on that region. The simplest way to rewrite the logic may be the introduction of new exception type(s) corresponding to the labels.
Re:Why Checked Exceptions Failed by crabbone on Saturday July 15, 2023 @12:07PM (#36738129)
This is very simplistic view of the problem. This completely glosses over modularity, ABI, performance optimizations... just to name a few.

How are you going to write generic functions that take functions as arguments and re-throw the errors thrown by these functions, if you use checked exceptions? Will you require that the acceptable functions only throw exceptions that you like? -- Then your generic function is close to being worthless...

If exceptions are encoded in function's interface, then they have to be in ABI, but then you must have non-trivial types available when marshalling data between two components, so, you cannot serialize the communication using some protocol with a fixed number of types (eg. JSON and friends), because now you need to account for the infinite variety of exception types.

Because of at least these two things, what I saw happen a lot of Java / C++ projects (god blessed me with very little C# exposure) was that as soon as a developer encountered a function with checked exceptions, a wrapper was written which changed the type into a runtime exception. This is so because exceptions are supposed to be handled separately, and often the author of the function has no idea how they need to be handled -- so they want to concentrate on the main goal of the function. Once functions grow into garlands of try-catch-catch-catch-...catch the focus is lost. It becomes very hard to understand why the function was written in the first place, because the error handling takes over every other concern.

Re:Why Checked Exceptions Failed by duped on Saturday July 15, 2023 @12:21PM (#36738306)
> Will you require that the acceptable functions only throw exceptions that you like? -- Then your generic function is close to being worthless...

Constrained generic parameters are actually super useful.

> If exceptions are encoded in function's interface, then they have to be in ABI

They already are in Itanium

> you cannot serialize the communication using some protocol with a fixed number of types (eg. JSON and friends), because now you need to account for the infinite variety of exception types.

No, the only exception that arises is ser/deserialization error. You can also trivially represent an error in JSON using an object, which is exactly what JSON RPC protocols do. It's also never safe to throw across an FFI boundary and similarly nonsensical to throw across a serialization boundary, so I'm not sure why you'd care.

Re:Why Checked Exceptions Failed by crabbone on Sunday July 16, 2023 @04:38AM (#36744828)
> Constrained generic parameters are actually super useful.

Then you missed the main point: if you require the generic function to accomodate all sorts of kinds of exceptions raised by the functions it may call, this requirements now propagates to every function it may call. So, you end up implementing functions with unnecessary "throws" because they might be used in a generic function which had to add that clause because of some other completely unrelated function.

Alternatively, you aren't writing generic code at all, you just write two implementations which happen to have similar names.

Re:Why Checked Exceptions Failed by interlocutor on Saturday July 15, 2023 @01:59PM (#36739399)
> write generic functions that take functions as arguments and re-throw the errors thrown by these functions

There is a philosophy that applies here: simple things should be simple, complex things should be possible. The scenario you're mentioning is not common enough that the language design should be centered around it.

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.
Re:Why Checked Exceptions Failed by dasyatidprime on Saturday July 15, 2023 @03:46PM (#36740290)
> How are you going to write generic functions that take functions as arguments and re-throw the errors thrown by these functions, if you use checked exceptions?

I've actually done this with an interface type parameter used in a throws clause in Java before, but I'm not sure how it interacts with module boundaries, it's kind of verbose, and it certainly didn't seem to be common practice. But it did work: the HOF-ish method that took a parameterized ThingFrobber<E> and used it to frob things unchecked would compile only if it also threw E, and the method passing the HOF a ThingFrobber (I think via lambda syntax) could catch the associated concrete checked exception type to sink it. IIRC I was using it to allow a checked early exit from a complex iteration, and it even propagated a slightly complex bound with multiple checked exception types more smoothly than I'd expected it to.

Re:Why Checked Exceptions Failed by iainmerrick on Saturday July 15, 2023 @05:18PM (#36741045)
Right, I was thinking that this is the answer to the supposedly intractable problem posed by the original article.

Just make your ExampleInterface generic -- ExampleInterface<T>.foo() throws T.

That technique works really well, and I don’t understand why it isn’t more widely used (or at least it wasn’t when I last used Java for serious work).

Re:Why Checked Exceptions Failed by osigurdson on Saturday July 15, 2023 @01:07PM (#36738881)
Exceptions are great when they don’t need to be caught. Otherwise they are a pain.
Re:Why Checked Exceptions Failed by _a_a_a_ on Saturday July 15, 2023 @01:32PM (#36739157)
Each 'leaf' statement of language should have a definite and finite list of exceptions that it can throw.

Each non-leaf statement is a composition of leaf statements. Therefore every exception can be determined, and that's our checked exceptions would work; work at the exceptions and check they match the list.

Therefore even without checked exceptions the compiler could provide the exceptions you want and you can check them or not if you please, so get the best of both worlds. All without forcing people to give an explicit list of exceptions everywhere. Forcing checked exceptions is not going to be popular, and much of the time is counter-productive.

Also someone broke your Liskof Substitution Principle which may be your bigger problem.