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

📄 exceptiondemo.java

📁 卡内基梅陇大学的网上教程 ssd3第一单元的源码
💻 JAVA
字号:
package unitOne;

/**
 * This class demonstrates exception throwing and catching.
 *
 * @author  iCarnegie
 * @version 1.0.0
 */
public class ExceptionDemo {

    /**
     * Calls methodA
     *
     * @param args  not used
     */
    public static void  main(String[] args)  {

        methodA();
        System.out.println("MethodA passed");
    }

    /**
     * Calls methodB. If an exception occurs; catches it, reports the
     * error, and terminate the program.
     */
    public static void  methodA()  {

        try {
            methodB();
            System.out.println("MethodB passed");
        } catch (Exception e) {
            e.printStackTrace();

            System.exit(1);
        }
    }

    /**
     * Calls methodC. If an exception occurs, throws it to the calling
     * method.
     *
     * @throws Exception  when methodC is called.
     */
    public static void  methodB() throws  Exception  {

        methodC();
        System.out.println("MethodC passed");
    }

    /**
     * Calls methodD. If an exception occurs, throws it to the calling
     * method.
     *
     * @throws Exception  when methodD is called.
     */
    public static void  methodC() throws  Exception  {

        methodD();
        System.out.println("MethodD passed");
    }

    /**
     * Throws an exception
     *
     * @throws Exception  whenever methodD is called.
     */
    public static void  methodD() throws  Exception  {

        throw new  Exception("This is an Exception Message");
    }
}


⌨️ 快捷键说明

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