News for hackers. Stuff that matters.
Re:Java’s Checked Exceptions Are Evil? (2015) by EdwardDiego on Sunday September 23, 2018 @09:04PM (#18054312)
> So listing exceptions that can be thrown is a good thing because it helps you write more reliable code.

This is entirely valid Java:

    public class FooBob {
    
        class ExampleException extends RuntimeException {
        
        }
    
        public boolean foo(Boolean bob) throws ExampleException {
            ...
        }
    }
You don't need to throw a checked exception to document that your public API throws an exception.

You're right, that throwing a new checked exception would force programmer B to handle it, but frankly, I'd rather that programmer B a) versioned his dependencies or b) read the source code of his dependencies.

Also, not sure about C# land, but in Java land, if you're writing libraries, we have tools to enforce semantic versioning based on public API changes (the Maven enforcer plugin with the semver plugin) which would also communicate breaking API changes.

I would much prefer that enforcing the communication of backwards-incompatible API changes not be done by the compiler.

There are no comments on this comment yet.