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 阅读(445) 评论(1)  编辑  收藏

评论

# re: 重掷异常时如何捕获这个异常? 2008-07-22 22:32 隔叶黄莺

要么在外层再加一个 try...catch 来捕获,扔到 main 外的话就只能让 JVM 去捕获了。  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航: