public class Rethrowing
{
public static void f() throws Exception
{
System.out.println("Rethrowing the Exception in f()");
throw new Exception("throw from f()");
}
public static void g() throws Exception
{
try
{
f();
}
catch(Exception e)
{
System.err.println("Inside g()");
e.printStackTrace();
throw e.fillInStackTrace();
}
}
public static void main(String[] args) throws Throwable
{
try
{
System.out.println("111");
g();
}
catch(Exception e)
{
System.err.println("Caught in main");
e.printStackTrace(); //显示的将是原来异常抛出点的调用栈信息,而并非重新抛出点的信息
}
}
}它报的错误是:未报的异常java.lang.Throwable;必须对其进行铺捉或声明以便抛出
{
public static void f() throws Exception
{
System.out.println("Rethrowing the Exception in f()");
throw new Exception("throw from f()");
}
public static void g() throws Exception
{
try
{
f();
}
catch(Exception e)
{
System.err.println("Inside g()");
e.printStackTrace();
throw e.fillInStackTrace();
}
}
public static void main(String[] args) throws Throwable
{
try
{
System.out.println("111");
g();
}
catch(Exception e)
{
System.err.println("Caught in main");
e.printStackTrace(); //显示的将是原来异常抛出点的调用栈信息,而并非重新抛出点的信息
}
}
}它报的错误是:未报的异常java.lang.Throwable;必须对其进行铺捉或声明以便抛出
{
public static void f() throws Exception
{
System.out.println("Rethrowing the Exception in f()");
//throw new Exception("throw from f()");
}
public static void g() throws Exception
{
try
{
f();
}
catch(Exception e)
{
System.err.println("Inside g()");
e.printStackTrace();
//throw new Exception("throw from f()");
//throw e.fillInStackTrace();
}
}
public static void main(String[] args) throws Throwable
{
try
{
System.out.println("111");
g();
}
catch(Exception e)
{
System.err.println("Caught in main");
e.printStackTrace(); //显示的将是原来异常抛出点的调用栈信息,而并非重新抛出点的信息
}
}
}