This is usually a bad practice. catch(Exception e)
(sometimes called Pokemon Exception Handling for when you gotta catch 'em all) catches every single exception. Such exception handling is rarely useful because:
- It catches runtime exception too.
- You lose information about the type of exception that was thrown.
- You cannot react to or handle specific exceptions.
Your method signature now is public void whatever() throws Exception
, which is rarely useful. Now everything further up the chain has no idea what kind of exception you have thrown; they will have to do instanceof
checks which defeats the purpose of catching specific-exceptions entirely.
As far as your second exception is concerned, throw e;
throws the same exception object. If you wanted to wrap the exception, you can create a new one, which means you would do something like throw new MyCustomException(e);
. You would also need to change your method signature.
If there is nothing further up the chain, I guess this isn't as bad (still isn't great, though). It looks like a method that is trying to log all exceptions that are thrown. However, again, there are better ways of doing this.