About Question enthuware.ocpjp.v11.2.3356 :
Posted: Fri Mar 26, 2021 9:51 am
Sorry but can you explain why compilation that part :
"However, if it will cause a compilation failure at line catch(WithdrawalException e){ of the main method because the compiler will notice that the code in the try block never throws WithdrawalException and the catch block is unreachable."
I mean by that logic - if WithdrawalException extends RuntimeException than why compiler doesn't say anything about "catch(WithdrawalException e){" in main method? Because method withdraw throws its superclass and not WithdrawalException anyway.
"However, if it will cause a compilation failure at line catch(WithdrawalException e){ of the main method because the compiler will notice that the code in the try block never throws WithdrawalException and the catch block is unreachable."
I mean by that logic - if WithdrawalException extends RuntimeException than why compiler doesn't say anything about "catch(WithdrawalException e){" in main method? Because method withdraw throws its superclass and not WithdrawalException anyway.