There are two cases that I can think of - the first such case I can think of is to implement finalize() , you need to throw Throwable :
@Override protected void finalize() throws Throwable { super.finalize(); }
... although keep in mind that some argue that using finalize should be discouraged on its own.
A potential second case is to use a (poorly written) library whose method can throw Exception , in which case if you do not want to deal with this particular method, the only option is to drop it onto the stack.
Personally, although if it were me, I would most likely wrap it in a RuntimeException, and then:
public void doSomething() { try { int x = libraryThing.badMethod(); //Library method that throws "Exception" } catch(Exception ex) { throw new RuntimeException("Couldn't do something", ex); } }
The second argument in the RuntimeException constructor RuntimeException important in this case, because if thrown, it will save the original exception in the stack trace as ("Caused by: x"). Of course, if you can find a more specific subclass of RuntimeException that you can guarantee is relevant in this context (e.g. IllegalArgumentException ), then using this would be better.
In terms of normal code, however, no - I would argue that it is almost always an anti-pattern (and usually it is simply caused by laziness!)
As a side point, throwing a RuntimeException not so bad - it is still very non-specific, but at least it does not make the caller explicitly catch everything.
source share