⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 finallydemo.java

📁 java编程代码
💻 JAVA
字号:

public class FinallyDemo
{
    public static void main(String[] args)
    {
        try
        {
            exerciseMethod(42);
        }
        catch(Exception e)
        {
            System.out.println("Caught in main.");
        }
    }
    public static void exerciseMethod(int n) throws Exception
    {
        try
        {
            if (n > 0) 
                throw new Exception( );
            else if (n < 0)
                throw new NegativeNumberException( );
            else 
               System.out.println("No Exception.");
            System.out.println("Still in sampleMethod.");
        }
        catch(NegativeNumberException e)
        {
            System.out.println("Caught in sampleMethod.");
        }

        finally
        {
            System.out.println("In finally block.");
        }
        System.out.println("After finally block.");
    }
}

⌨️ 快捷键说明

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