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

📄 ex28.java

📁 java编程思想第四版习题答案
💻 JAVA
字号:
// exceptions/Ex28.java
// TIJ4 Chapter Exceptions, Exercise 28, page 500
/* Modify Exercise 4 so that the custom exception class inherits from
* RuntimeException, and show that the compiler allows you to leave
* out the try block.
*/

class Exception28 extends RuntimeException {
	private String msg;
	Exception28(String msg) {
		super(msg);
		System.out.println("Exception28()");
		this.msg = msg;
	}
	protected void showS() {
		System.out.println("Message from Exception4: " + msg);
	}
}

public class Ex28 {
	public static void f() throws Exception28 {
		System.out.println("f()");
		throw new Exception28("Ouch from f()");
	}
	public static void main(String[] args) {
		f();
	}
}

⌨️ 快捷键说明

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