IOException
only has 2 constructors: IOException()
and IOException(String s)
. So you can't pass a cause exception or throwable to these constructors. To do that, you will need to do something like this:ZipException ze = new ZipException("Nested ZipException");In JDK 6, 2 additional constructors are added:
IOException e = new IOException("IOException with nested ZipException");
e.initCause(ze);
throw e;
IOException(String s, Throwable cause)So the following can compile and run fine in JDK 6 and later:IOException(Throwable cause)
ZipException ze = new ZipException("Nested ZipException");but will fail to compile in JDK 1.5 or earlier:
IOException e = new IOException(ze);
throw e;
/cygdrive/c/tmp > javac -version A.javaSee IOException javadoc in JDK 1.5 and JDK 6.
javac 1.5.0_06
A.java:15: cannot find symbol
symbol : constructor IOException(java.util.zip.ZipException)
location: class java.io.IOException
IOException e = new IOException(ze);
^
1 error
Tags: