Adobe Interview Question
Software Engineer / DevelopersCountry: United States
Generally nested try-catch are managed by stacks. Like a function, try-catch block will define a range of bytecode and push an address (the code inside catch) onto the stack. A throw statement basically jump to the catch block(s), and pop the address from the stack. If no handle is defined, then we recursively jump & pop until the stack is empty. At this point, it becomes an unhandled exception and the program quits.
Each try-catch-finally block is associated with an Exception handler in the JVM. If there is no exception handler in the thread where exception happens the thread exits and it's status is returned to the JVM.
well, JVM generally gives a default handler for not handled exception ... This is the concept related to exception propagation, Right?? But how this handler complete the task??
From "Inside the Java 2 VM" Chapter 17 by Bill Venners:
- ms January 29, 2013If this situation (i.e., exception) occurs, the JVM knows to jump to the bytecode sequence that implements the catch clause by looking up and finding the exception in a table. Each method that catches exceptions is associated with an exception table that is delivered in the class file along with the bytecode sequence of the method. The exception table has one entry for each exception that is caught by each try block.