I am trying to pass e
of type IOException
as 开发者_如何学Gothe cause in a new IOException
as shown below.
try {
//stuff
}
catch (IOException e) {
throw new IOException("Some Message", e);
}
This gives me the error below:
The constructor IOException(String, IOException) is undefined
However, in 1.6, IOException(String, Throwable)
is implemented as a constructor for this class.
It's like I'm in Java 1.5, even though everything in my project properties says 1.6! I don't even have a 1.5 JDK installed on my hard drive!
The Java version on Androind only implements 1.5 features. You should be able to use the initCause method like this:
IOException e2 = new IOException("Some message");
e2.initCause(e);
throw e2;
Try doing this inside your catch instead:
throw new IOException("Some Message", e.getCause());
I was referencing the incorrect android.jar in my project setup.
Also note that this constructor was introduced in the Android API in API Level 9. If you're using anything below that, then you won't be able to use it. – Joachim Sauer Aug 4 at 14:44
精彩评论