lostmessage18.java

来自「java编程思想第四版习题答案」· Java 代码 · 共 59 行

JAVA
59
字号
// exceptions/LostMessage18.java
// TIJ4 Chapter Exceptions, Exercise 18, page 479
// Add a second level of exception loss to LostMessage.java so that the
// HoHumException is itself replaced by a third exception.

class VeryImportantException extends Exception {
	public String toString() {
		return "A very important exception!";
	}
}

class HoHumException extends Exception {
	public String toString() {
		return "A trivial exception";
	}
}

class MeaninglessException extends Exception {
	public String toString() {
		return "A meaningless exception";
	}
}

public class LostMessage18 {
	void f() throws VeryImportantException {
		throw new VeryImportantException();
	}
	void dispose() throws HoHumException {
		throw new HoHumException();
	}
	void eliminate() throws MeaninglessException {
		throw new MeaninglessException();
	}
	public static void main(String[] args) {
		try {
			LostMessage18 lm = new LostMessage18();
			try {
				try {
					lm.f();
					lm.dispose();
				} finally {
					lm.eliminate();
				}
			} catch(Exception e) {
				System.out.println(e);
			}
		} catch(Exception e) {
			System.out.println(e);
		}
	}
}

 
 
 
 

 

⌨️ 快捷键说明

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