sneaky throwing

Andy Nuss andrew_nuss at yahoo.com
Thu Jan 9 20:39:19 PST 2014


Hi,

I had a lot of reasons to sneaky throw exceptions just as they are but without having the function that throws them declare the exception.  This saves me alot of trouble, especially with reflective errors that I know shouldn't ever happen.

To do this, I declared an interface that throws Throwable and the throwing function taking a single argument, the Throwable, and just providing a simple implementation for it.  Compiled to a .class and saved the byte code file as a small hex string.  Meanwhile, I declared another version of the interface that is identical in every way except that it does not declare that its throwing function throws Throwable.  I then use the saved bytecodes as the implementation for this interface, and use a singleton to provide the public static function.  Apparently, at the bytecode level, this is ok.

This has worked nicely all the way from JDK4 to JDK7.  Will it work with JDK8?  For example, lets say I have a tomcat servlet which throws 2 kinds of declared exceptions.  But I in fact sneaky throw many others during development.  This is ok right now.


Andy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20140109/8a45b6d0/attachment.html 


More information about the hotspot-compiler-dev mailing list