You're very likely to get some of the latter sneaking in with an interface change like the above. The person who made the change is going to be the one who gets stuck getting the code to compile. If they are faced with tens (maybe even hundreds) of compile errors, they're going to be forced to make a whole bunch of unplanned changes to a bunch of code they didn't write and might poorly understand even before they can get to the point of being able to start running the unit tests.
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.
And of course writing "throws Exception" on every single test is hugely annoying. Yes, I do not want to handle exceptions in the tests, that's the whole point of the test!
if(!isInstalled(Foo)) {
purchase(Foo)
} else {
start(Foo)
}
Programmer A writes this C# code:
Programmer B calls the above code like this: Later programmer A updates his code because there are newer versions of Foo and he needs the newest version: Now the code written by Programmer B crashes even though it compiles fine. That's bad.Had this been Java, programmer would be would be alerted to the fact that he needs to decide what do do if the version of Foo is too old. This is good.
So listing exceptions that can be thrown is a good thing because it helps you write more reliable code. If you are lazy you can always defeat the system by declaring your method as throwing a parent (or the root) exception class, in which case it is no worse than C#.