Let me give you small example to understand “Ducking” the exception.
We know, methods are getting pushed to stack for execution. In the below picture:
main() method is calling method1()
method1() is calling method2()
method2() is calling method3()
- A/An checked/unchecked exception occurred at method3().
- That exception is not either handled or declared at method3() block. Then the runtime system will try to popper from the stack and come back to method2().
- At method2() level, follow step:2
- At method1() level, follow step:2
- At main() level, follow step:2
- main() method will complete and JVM will exit and normal flow of the program is interrupted.\
For fixing this scenario, we need to understand “Handle” or “Declare” mechanism.