//自定义异常类的格式:
public class 异常类名 extends Exception {
无参构造
带参构造
}
public class DotcppException extends Exception {
//无参构造
public DotcppException() {
} //带参构造
public DotcppException(String message) {
//异常错误消息
super(message);
}
}
Java try…catch…finally语句里return语句的执行顺序(1)
public class Main {
public static void main(String[] args) {
System.out.println(test1());
}
public static int test1() {
int i =10;
try {
System.out.println("try语句");
return --i;
}
catch (Exception e) {
System.out.println("catch语句");
}
finally {
System.out.println("finally语句");
}
return 0;
}
}
Java try…catch…finally语句里return语句的执行顺序(2)
public class Main {
public static void main(String[] args) {
System.out.println(test2());
}
public static int test2() {
int i =10;
try {
System.out.println("try语句");
return --i;
}
catch (Exception e) {
System.out.println("catch语句");
}
finally {
System.out.println("finally语句");
return --i;
}
}
}