If I have a try block that throws a RuntimException subclass, can a subsequent catch block catches it as an Exception? Specifically:
public class MyAppException extends RuntimeException {
// ....
}
// In some other part of the code:
try {
// Executing this results with doSomething() throwing a MyAppException.
int x = doSomething();
} catch(Exception exc) {
// Does the thrown MyAppException get caught here?
}
My thinking is yes, because a RuntimeException extends Exception. However I have some production code that is not behaving this way. So obviously, if the answer is no, then that’s my answer; otherwise I need to dig down and see why my code is breaking bad. Thanks in advance!
Yes. It will catch
RuntimeExceptionbut in case anyExceptionarise in catch block that you have to catch again.I would suggest you to make a local deployment and debug the code.