About Question enthuware.ocpjp.i.v11.2.826 :
Posted: Fri Jun 26, 2020 12:56 am
So MyException is unable to catch any exception except ItSelf ?
What if you want MyException to be able to catch ArrayIndexOutOfBoundsException, what would the code inside class MyException look like? Or is this outside of the scope for the test?
Or, alternatively, to be able to catch ArrayIndexOutOfBoundsException, is this how we would do it with the limited knowledge that we have for this test?
In summary, I want to make the conclusion that a custom exception that extends Exception/Throwable is pretty much useless for catching any other type of error/exception. It can only catch itself.
Although I will not conclude this hypothesis for now, I think custom code can be added to MyException for it to be able to catch other exceptions/errors, but I don't know if that is outside of the scope of the test or not.
What if you want MyException to be able to catch ArrayIndexOutOfBoundsException, what would the code inside class MyException look like? Or is this outside of the scope for the test?
Or, alternatively, to be able to catch ArrayIndexOutOfBoundsException, is this how we would do it with the limited knowledge that we have for this test?
Code: Select all
try{
doTest();
}
catch(MyException me){
System.out.println(me);
} catch (ArrayIndexOutOfBoundsException e){ }
Although I will not conclude this hypothesis for now, I think custom code can be added to MyException for it to be able to catch other exceptions/errors, but I don't know if that is outside of the scope of the test or not.