You Know IOException? Think Again!

I was amazed today to find out that there was no constructor IOException(String, Throwable) or IOException(Throwable) in JDK1.4 and JDK1.5. It is finally in JDK1.6, I can’t believe it took Sun that much time to change that.

So the workaround is:

IOException ioe = new IOException(“message”);
ioe.initCause(e);
throw ioe;
It can also be written as:
throw (IOException) new IOException(“message”).initCause(e);
It is not a major problem, but still. We can all thank the guy who reported that as a bug to Sun in 2004.

comments powered by Disqus
Tweet Submit to reddit
© 2006-16 Fabien Creative Commons License This work is licensed under a Creative Commons Attribution 4.0 International License.