public class Rethrowing
{
public static void f() throws Exception
{
System.out.println("Throwing a Exception from f()");
throw new Exception("from f()");
}
public static void g() throws Throwable
{
try
{
f();
}
catch(Exception e)
{
System.err.println("Inside g(),e.printStackTrace()");
e.printStackTrace(System.err);
//throw e;
throw e.fillInStackTrace();
}
}
public static void main(String [] args) throws Throwable
{
try
{
g();
}
catch(Exception e)
{
System.err.println("Caught in main,e.printStack()");
e.printStackTrace(System.err);
}
}
}
问题是主函数为什么要加上throws Throwable? 如果g()中返回的是Throwable 那么主函数中的catch()将不会捕捉的啊 敬请高手指点~~~
{
public static void f() throws Exception
{
System.out.println("Throwing a Exception from f()");
throw new Exception("from f()");
}
public static void g() throws Throwable
{
try
{
f();
}
catch(Exception e)
{
System.err.println("Inside g(),e.printStackTrace()");
e.printStackTrace(System.err);
//throw e;
throw e.fillInStackTrace();
}
}
public static void main(String [] args) throws Throwable
{
try
{
g();
}
catch(Exception e)
{
System.err.println("Caught in main,e.printStack()");
e.printStackTrace(System.err);
}
}
}
问题是主函数为什么要加上throws Throwable? 如果g()中返回的是Throwable 那么主函数中的catch()将不会捕捉的啊 敬请高手指点~~~
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货