I never did any serious Java coding before, but I learned the syntax, libraries, and concepts based on my existing skills (Delphi & C#). One thing I hardly understand i
In C# all exceptions are runtime exceptions, but in Java you have runtime exceptions and checked exceptions, that you have to either catch, or declare in your methods. If you call any method that has a "throws" at the end, you have to either catch the exceptions mentioned there, or your method has to also declare those exceptions.
Java Articles usually just print the stack trace or have a comment because the exception handling is irrelevant to the article's subject matter. In projects though, something should be done about it, depending on the type of exception.
because Checked Exceptions is a failed experiment
(maybe printStackTrace() is the real problem? :)
I think developers also try to consider the importance of "doing the right thing" in a particular context. Often times for throw away code or when propagating the exception upwards wouldn't buy anything because the exception is fatal, you might as well save time and effort by "doing the wrong thing".
The real point of exceptions is to simplify error handling and separate it from error detection. This is in contrary to representing errors by error codes, where error handling code is scattered everywhere and every call which may fail shall be checked for return code.
If exception represents an error (which is most of the cases) usually the most reasonable way to handle it is to bail out and leave the handling to some upper layer. Rethrowing different exception should be considered if some meaningful semantics is added to it i.e., this error is an unusual system failure / temporary (networking) problem / this is client or server side error etc.
Of all error handling strategies the most ignorant is hiding or simply printing error message and going forward as nothing happened.
Sun folks wanted the code to be more explicit and forced programmers to write which exceptions may be thrown by which method. It seemed to be right move -- anybody will known what to expect in return from any method call given it's prototype (it may return value of this type or throw an instance of one of the specified classes (or it's subclass)).
But as it turned out with lots of ignorant Java programmers they now treat exception handling as if it was a language bug/"feature" which needed a workaround and write code in worst or almost worst possible way:
How to write the "right way" than?
Usually that is due to the IDE offering a helpful 'quick fix' that wraps the offending code in a try-catch block with that exception handling. The idea is that you actually DO something, but lazy developers don't.
This is bad form, no doubt.