I have a piece of code where I capture all exceptions and throw one generic exception at the end. Something like this:
try {
// do something here
} catch (Whatever e) {
throw new MyException(e.getMessage());
}
This kind of makes my function definition looks clean, i.e. "myFunc throws MyException" but at the same time I lose the semantics of what caused the problem. On the other hand if I just throw all exceptions, that will make the function body cleaner but the definition of the function will contain 1-5 throw statements.
My question is: what is better?... should I capture all exceptions, keeping the function definition clean, or should I throw everything keeping the body of the function clean?
NOTE: the second approach will also make the exception handling code for my function more difficult...