allocation-instrumenter icon indicating copy to clipboard operation
allocation-instrumenter copied to clipboard

What happens if the constructor throws exception?

Open l0rinc opened this issue 6 years ago • 3 comments

I.e. can it handle the case that Byte Buddy can't yet (see: https://github.com/raphw/byte-buddy/issues/375), when constructors throw exceptions?

l0rinc avatar Jan 05 '19 12:01 l0rinc

Allocation instrumentation runs the handler when the new bytecode (or equivalent) is called. So, it is handled in that case.

Constructor instrumentation doesn't handle that case. I probably won't have time to add it, although I could take a patch.

jhmanson avatar Jan 06 '19 07:01 jhmanson

How do you imagine it being done, since we can't just insert a try/catch around the constructor body?

l0rinc avatar Jan 13 '19 08:01 l0rinc

I guess I'm not sure I understand the problem. "try" and "catch" and "finally" are source level constructs, not bytecode level ones. In bytecode, you have an exception table that lists ranges of bytecodes, and their associated exception handler. I don't know of anything that would stop you from having an exception handler whose range of bytecode encompasses the entire constructor.

That said, it has been a while since I looked at the spec. Maybe there is something there?

jhmanson avatar Jan 14 '19 05:01 jhmanson