我有一个设置,例如...
public class MyClass {
Exception e = null;
try {
Game.runItNow();
} catch (Exception e) {
this.e = e;
}
if (this.e == null) {
showError();
}
}
public class Game {
public static void runItNow() throws IOException {
try {
HttpManager.getData()
} catch(IOException e) {
// here, e = null
throw e;
}
}
}
public class HttpManager {
public static String getData() throws IOException {
String someData = "The fox is brown";
String someWord = "fox";
if (someData.contains(someWord)) {
throw new IOException();
}
return someData;
}
}
问题是,当我捕捉到 IO 异常时e == null
...... 不确定我是否有脑放屁,但我很困惑。为什么是e == null
?我正在抛出它的一个新实例。