Paul Yule wrote:I would avoid creating an empty catch block. Do something with the error like simply printing it to a log. Otherwise, later down the line you might run into some trouble when suddenly things don't work but everything looks a-ok.
Excellent advice. The least
you should do is print the exception.
Only if you are really really really really really really 100.00000% sure the exception won't occur you can ignore it, but even then you should put a comment on why it won't occur. An example I once wrote, that calls an object's clone method through reflection:
The first two exceptions are guaranteed to not happen, because at the moment invoke is called there is 100% surely a public method called clone() without any parameters. Granted, ignoring the last exception may not be nice, but the Javadoc said that null would be returned upon error.