我想知道是否有人遇到过奇怪的行为..我有try / catch块,其中catch语句分配一个异常变量以使我能够正确处理异常。
我得到的是catch(Exception ex)语句中的ex = null。
我做错了什么,拜托?
public class HelloWorldAndroidActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello world!");
try {
ExceptionTest et = new ExceptionTest();
et.throwExeption();
} catch (Exception ex) {
System.out.println(ex);
}
setContentView(tv);
}
}
public class ExceptionTest {
public String throwExeption() throws Exception {
throw new Exception("Crash!");
}
}