Java Exception PropagationAn exception is first thrown from the top of the stack and if it is not caught, it drops down the call stack to the previous method. If not caught there, the exception again drops down to the previous method, and so on until they are caught or until they reach the very bottom of the call stack. This is called exception propagation. Note: By default Unchecked Exceptions are forwarded in calling chain (propagated).Exception Propagation ExampleTestExceptionPropagation1.java Test it NowOutput: exception handled normal flow... In the above example exception occurs in the m() method where it is not handled, so it is propagated to the previous n() method where it is not handled, again it is propagated to the p() method where exception is handled. Exception can be handled in any method in call stack either in the main() method, p() method, n() method or m() method. Note: By default, Checked Exceptions are not forwarded in calling chain (propagated).Exception Propagation ExampleTestExceptionPropagation1.java Test it NowOutput: Compile Time Error Next TopicThrows Keyword |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India