ex28(1).java

来自「JAVA编程思想第四版英文原版习题答案. pdf原版的」· Java 代码 · 共 28 行

JAVA
28
字号
// 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 + =
减小字号Ctrl + -
显示快捷键?