Think about this sample code:
...
try {
stm1
stm2
stm3
} catch(){
...
}
...
Suppose to run the code and within the try block an exception is raised. Execution flow goes into the catch block.
Here, I would like to copy the bytecode of the try block (maybe using ASM), apply some modifications to the bytecode (for example substitute stm2 with stm4) and execute the new piece of bytecode within the catch block.
Is this possible without compiling or loading the new bytecode, but just executing it like an interpreted language?
Thank you!
UPDATE
I know that I can write the right piece of code a priori. The question is not why, but how to do that and if it is possible.
Suppose that I have to compute the new try body dynamically and that I have to execute the new code within the same object (because of the local variables and class variables.)