nested-exceptions

Best way to check whether a certain exception type was the cause (of a cause, etc ...) in a nested exception?

I am writing some JUnit tests that verify that an exception of type MyCustomException is thrown. However, this exception is wrapped in other exceptions a number of times, e.g. in an InvocationTargetException, which in turn is wrapped in a RuntimeException. What's the best way to determine whether MyCustomException somehow caused the exc...

How Should I Move A File On Exception?

The requirement: On an error (thrown exception), the file being processed should be moved to the folder for files with errors (app.config setting). The problem: The only way that I can of handling this is to have a nested Try/Catch inside of the main Try/Catch to try to move the file, that way if the move fails, another exception is...

Catching an exception that is nested into another exception

Hi, I want to catch an exception, that is nested into another exception. I'm doing it currently this way: } catch (RemoteAccessException e) { if (e != null && e.getCause() != null && e.getCause().getCause() != null) { MyException etrp = (MyException) e.getCause().getCause(); ... } else { ...

Should exceptions be chained in C++?

Hello, This may have been asked previously, but I search the stack and couldn't find any which really hit upon this. I just finished work on a C++-program where I've implemented my own exceptions (although derived from std::exception). The practice I've applied when one exception causes a chain reaction, propagating the error upwards a...

How does this implementation of chaining exceptions work?

Hello, I previously asked a question about how to chaining exceptions in C++, and one of the answers provided a nifty solution to how it can be done. The problem is that I don't understand the code, and trying to have this kind of discussion in the comments is just too much of a bother. So I figured it's better to start a new question e...