It seems the parent class method throws any child or sibling of RuntimeException, and the child throws RuntimeException this is ok. THe compiler accepts it and even runs the program.
However when parent class method throws any child or sibling of RuntimeException, and the child throws Exception this is not ok
In the above code change RuntimeException to Exception ...
I'm having a hard time understanding this, can anyone explain this rule?
In case of overriding child class method can not throws wider exception than parent class method in case of checked exception,
but in case of Runtime exception there i no such restriction,
you are throwing Exception in child class and this dose not come under Runtime
so it will not work
Some time it also good to catch the exception and show some other suitable exception from method, called exception chaining though you need to include original exception as source for more information on stack trace.