我想知道是否有人遇到奇怪的行为。我有 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!");
}
}
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)