Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What happens if the constructor throws exception? #31

Open
l0rinc opened this issue Jan 5, 2019 · 3 comments
Open

What happens if the constructor throws exception? #31

l0rinc opened this issue Jan 5, 2019 · 3 comments

Comments

@l0rinc
Copy link

l0rinc commented Jan 5, 2019

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

@jhmanson
Copy link
Contributor

jhmanson commented Jan 6, 2019

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.

@l0rinc
Copy link
Author

l0rinc commented Jan 13, 2019

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

@jhmanson
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants