dance-elephant

          常用鏈接

          統計

          Ant

          最新評論

          重擲異常時如何捕獲這個異常?

          class OneException extends Exception {
           public OneException(String s){
            super(s);
           }
          }
          class TowException extends Exception{
           public TowException(String s){
            super(s);
           }
          }
          public class RethrowNew{
           public static void f()throws OneException{
            System.out.println("originationg the exception in f()");
            throw new OneException("thrown from f()");
           }
           public static void main(String[] agrs)throws Throwable{
            try{
             f();
            }
            catch(OneException e){
             System.err.println("caught in main,e.printstacktrace()");
             e.printStackTrace(System.err);
             throw e;
            }
           }
          }
          在main()的catch()中我拋出異常e:throw e;但不知這個異常如何被捕獲,哪位
          高手可以幫小弟解決一下啊。
          上述程序的運行結果如下:
          originationg the exception in f()
          caught in main,e.printstacktrace()
          OneException: thrown from f()
           at RethrowNew.f(RethrowNew.java:15)
           at RethrowNew.main(RethrowNew.java:19)
          Exception in thread "main" OneException: thrown from f()//不知道這段信息如何出來
           at RethrowNew.f(RethrowNew.java:15)
           at RethrowNew.main(RethrowNew.java:19)

          posted on 2008-07-15 16:35 dance_elephant 閱讀(463) 評論(1)  編輯  收藏

          評論

          # re: 重擲異常時如何捕獲這個異常? 2008-07-22 22:32 隔葉黃鶯

          要么在外層再加一個 try...catch 來捕獲,扔到 main 外的話就只能讓 JVM 去捕獲了。  回復  更多評論   


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 连平县| 临猗县| 青州市| 华容县| 沈阳市| 孝昌县| 蒲城县| 蕲春县| 当雄县| 阜平县| 晋城| 崇明县| 广丰县| 夏津县| 松江区| 宝应县| 河间市| 平罗县| 清镇市| 临颍县| 绥滨县| 遵化市| 湄潭县| 明水县| 县级市| 漾濞| 罗源县| 木兰县| 普格县| 龙泉市| 柳州市| 伊金霍洛旗| 额敏县| 塔河县| 崇阳县| 五华县| 荣昌县| 万州区| 贵州省| 营山县| 新蔡县|