I know that RunTimeExceptions can be caught by Exception catch block as below.
public class Test { public static void main(String[] args) { try { throw new RuntimeException("Bang"); } catch (Exception e) { System.out.println("I caught: " + e); } } } I have my own created exception class as below.
public class CustomException extends Exception { public CustomException(String message, Throwable cause) { super(message, cause); } public CustomException(String message) { super(message); } } But now instead of keeping Exception in catch block, i kept CustomException.But run time exception is not caught by catch block now. Why?
public class Test { public static void main(String[] args) { try { //consider here i have some logic and there is possibility that the logic might throw either runtime exception or Custom Exception throw new RuntimeException("Bang"); } catch (CustomException e) { System.out.println("I caught: " + e); } } } Thanks!
