要求大概就是:
1.一个包装了的异常类
package com;
public class MyException extends Exception {
private static final long serialVersionUID = -1358391624708239344L;
public MyException() {
super();
}
public MyException(String message) {
super(message);
}
public MyException(String message, Throwable cause) {
super(message, cause);
}
public MyException(Throwable cause) {
super(cause);
}
public String getMyMessage() {
return "你的姓名" + getMessage();
}
}
2.一个异常产生类
package com;
public class ExceptionMaker {
public void throwException() throws MyException {
try {
throw new IllegalArgumentException();
} catch (IllegalArgumentException e) {
throw new MyException(e);
}
}
}
3.一个测试类
package com;
public class MyExceptionTest {
public static void main(String[] args) {
ExceptionMaker exceptionMaker = new ExceptionMaker();
try {
exceptionMaker.throwException();
} catch (MyException e) {
System.out.println(e.getMyMessage());
}
}
}