How JVM handles exceptions
The JVM handles exceptions through a structured mechanism involving bytecode instructions and an exception table. When an exception is thrown, the JVM looks up the appropriate handler in the method's exception table. Handlers can be catch or finally blocks, and each handler specifies a range of instructions it covers and a target address where execution should continue. If no handler is found, the JVM looks up the call stack until it finds an appropriate handler, executing any finally blocks it encounters along the way.