In Java I have a Exception class that extends from Exception
, But whenever I throw it, the compiler says that it needs to be caught/ must declare that methods throws
Exception.
When I use a RuntimeException
that extends from Exception
, the compiler does not stop, It takes them as Runtime Exception and we need not handle it.
Is there a way where I can make a MyException extend from Exception and still have it as runtime exception.? or What makes this as possibility in class RuntimeException
private void compileTime() throws MyException{
throw new MyException();
}
private void runTime() {
throw new MyRuntimeException();
}
class MyException extends Exception {
}
class MyRuntimeException extends RuntimeException {
}