1、try - catch的用法
1 public void test() {
2 try {
3 // TODO Somethings
4 } catch (Exception e) {
5 // TODO Otherthings
6 throw e;
7 }
8 System.out.println("print me");
9 }
上面的代碼在做了,異常處理之后就不執行
System.out.println("print me");
這一語句了,
但是要讓程序繼續執行,只要刪除catch里面的
throw e;
如下
1 public void test() {
2 try {
3 // TODO Somethings
4 } catch (Exception e) {
5 // TODO Otherthings
6 }
7 System.out.println("print me");
8 }
這樣就會繼續執行
System.out.println("print me");
2、變量聲明規約
變量的聲明應該遵循,變量使用范圍最小化的原則。
比如說:能在try里面聲明的就不要跑到方法頭去聲明。
posted on 2009-07-24 10:49
狼人 閱讀(436)
評論(0) 編輯 收藏 所屬分類:
Java