Cici_whatever
2015-03-11 11:09
为什么“喝车别开酒”我打印不出来……
你贴一下完整的代码,可能是自定义异常的时候构造方法没有传入一个字符串,我的代码:
/** 自定义异常 */
class DuckException extends Exception {
public DuckException(String string) {
super(string);// 构造带指定详细消息的新异常
}
}
public class Test {
public static void main(String[] args) {
try {
test();
} catch (DuckException e) {
e.printStackTrace();// 打印异常
}
}
private static void test() throws DuckException {
throw new DuckException("开车别喝酒!");
}
}
异常没有抛出吧。
Java入门第三季
409776 学习 · 4546 问题
相似问题