rethrowing.java

来自「我在学习JAVA的讲义」· Java 代码 · 共 24 行

JAVA
24
字号
//Demonstrating fillInStackTrace( )
public class Rethrowing
{   public static void f( ) throws Exception
    {   System.out.println("在 f( ) 中发生一个异常");
        throw new Exception("从 f( ) 中抛出的异常");
    }
    public static void g( ) throws Throwable
    {   try
        {   f( );}
        catch(Exception e)
        {   System.out.println("在 g( ) 中的异常路径,e.printStackTrace( )");
            e.printStackTrace( );
            throw e;        
        }
    }
    public static void main(String args[ ]) throws Throwable
    {   try
        {   g( );}
        catch(Exception e)
        {   System.out.println("在主方法中捕捉到异常,e.printStackTrace( )");
            e.printStackTrace( );
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?