异常类的构造方法除了空和String类型外能不能使用多个String类型参数, 如Exception(str1, str2, str3);
请看下面代码:
public class Test {
public static void main(String[] args) {
try{
m1();
}
catch(Exception ex) {
ex.printStackTrace();
}
} public static void m1() {
try {
m2();
}
catch(Exception ex) {
throw new Exception("New ingo form method1", ex);
//这里怎么有两个参数, 而且ex也不是String类型的
}
} public static void m2() {
throw new Exception("New ingo form method2");
}
}
请看下面代码:
public class Test {
public static void main(String[] args) {
try{
m1();
}
catch(Exception ex) {
ex.printStackTrace();
}
} public static void m1() {
try {
m2();
}
catch(Exception ex) {
throw new Exception("New ingo form method1", ex);
//这里怎么有两个参数, 而且ex也不是String类型的
}
} public static void m2() {
throw new Exception("New ingo form method2");
}
}
构造详细消息为 null 的新异常。
Exception(String message)
构造带指定详细消息的新异常。
Exception(String message, Throwable cause)
构造带指定详细消息和原因的新异常。
Exception(Throwable cause)
根据指定的原因和 (cause==null ? null : cause.toString()) 的详细消息构造新异常(它通常包含 cause 的类和详细消息)。