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

📄 exceptiondemo.java

📁 一些JAVA程序
💻 JAVA
字号:
/*!Begin Snippet:file*/
/**
 * 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");
	}
}
/*!End Snippet:file*/

⌨️ 快捷键说明

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