I'm trying to write some code that catches a particular exception and throw a more useful one for something higher up the call stack to deal with but also catch more general exceptions and handle them.
The code is something like this:
try { // Do stuff } catch (SomeException e) { throw new SomeExceptionWithContextInfo(); } catch (Exception e) { // Handle unexpected exception gracefully } The problem I'm having is that the general exception is catching my new exception. is there a way to avoid this?
My current solution involves checking the type of the exception and throwing it again if it's type is what I just created.