Tutorial by Examples

This example is about deliberately ignoring or "squashing" exceptions. Or to be more precise, it is about how to catch and handle an exception in a way that ignores it. However, before we describe how to do this, we should first point out that squashing exceptions is generally not the co...
A common thought pattern for inexperienced Java programmers is that exceptions are "a problem" or "a burden" and the best way to deal with this is catch them all1 as soon as possible. This leads to code like this: .... try { InputStream is = new FileInputStream(fileName);...
While catching the Throwable, Exception, Error and RuntimeException exceptions is bad, throwing them is even worse. The basic problem is that when your application needs to handle exceptions, the presence of the top level exceptions make it hard to discriminate between different error conditions. ...
As already pointed out in other pitfalls, catching all exceptions by using try { // Some code } catch (Exception) { // Some error handling } Comes with a lot of different problems. But one perticular problem is that it can lead to deadlocks as it breaks the interrupt system when writ...
There is a mantra that some Java experts are wont to recite: "Exceptions should only be used for exceptional cases." (For example: http://programmers.stackexchange.com/questions/184654 ) The essence of this is that is it is a bad idea (in Java) to use exceptions and exception handli...
One of the more annoying things that programmers can do is to scatter calls to printStackTrace() throughout their code. The problem is that the printStackTrace() is going to write the stacktrace to standard output. For an application that is intended for end-users who are not Java programmers,...
Throwable has two direct subclasses, Exception and Error. While it's possible to create a new class that extends Throwable directly, this is inadvisable as many applications assume only Exception and Error exist. More to the point there is no practical benefit to directly subclassing Throwable, as ...

Page 1 of 1