Is it possible to construct a snippet of code in Java that would make a hypothetical java.lang.ChuckNorrisException uncatchable?
Thoughts that came to mind are using for example interceptors or aspect-oriented programming.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I haven’t tried this, so I don’t know if the JVM would restrict something like this, but maybe you could compile code which throws
ChuckNorrisException, but at runtime provide a class definition ofChuckNorrisExceptionwhich does not extend Throwable.UPDATE:
It doesn’t work. It generates a verifier error:
UPDATE 2:
Actually, you can get this to work if you disable the byte code verifier! (
-Xverify:none)UPDATE 3:
For those following from home, here is the full script:
Create the following classes:
Compile classes:
Run:
Comment out “extends RuntimeException” and recompile
ChuckNorrisException.javaonly :Run:
Run without verification: