Login with  Log in with facebook
Hiring Manager? SIGN UP HERE
3

What is Stack Unwinding in Java?

Rishi Yadav
08/06/2011 at 19:21
1 Answer
1
1

Stack Unwinding:-- Stack follws LIFO(Last In First Out) method. So in exception handling when an exception is thrown ,when the try block exits it is handled by stack unwinding method.

When an exception is thrown but not caught in a particular scope, the method-call stackis “unwound,” and an attempt is made to catch the exception in the next outer try block.This process is called Stcak unwinding. 

For example if a method throws exception if it cannot handle it will finalize or declare that it cannot handle. Then the class or method by which it is called will handle it. The process goes on till it reaches main method. Even if it cannot handle the it is handles by user.

 

foo4()   |

foo3()   |

foo2()   |   Handled from top to bottom LIFO. Stack is unwinded.

foo1()   |   If foo4 throws exception it is handled by foo3.if foo3 cannot handle foo2 will handle. 

main()  |   If foo2 cannot foo1 will handle and if foo1 cannot main will handle. So stack is poping out each stack frame which is nothing but stack is unwinded.

 

Sunita Priyadarsini Pokkunuri
08/07/2011 at 13:00

If you want to post any answer to this forum then you need to log in.
Schedule a Demo

Schedule a Demo with us

Name *
Email *
Phone *
Company *
Details