# 1
```java
public class Domo01 {
public static void main(String[] args) {
int divisor = 100;
int dividend = 10;
try {
System.out.println(divisor/dividend);
}catch (Exception e) {
// e.printStackTrace();
System.out.println("除數(shù)不能為0");
} finally {
// 資源的釋放
System.out.println("必須要執(zhí)行的步驟蜀铲,一定會執(zhí)行");
}
System.out.println("666666");
}
}
2
public class Domo02 {
public static void main(String[] args) {
/*
int[] a = new int[2];
Scanner scanner = new Scanner(System.in);
try {
int i = scanner.nextInt();
int j = scanner.nextInt();
a[0] = i;
a[1] = j;
System.out.println(a[0] + a[1]);
}catch (IndexOutOfBoundsException e) {
System.out.println("越界異常");
}catch (InputMismatchException e) {
System.out.println("數(shù)據(jù)格式不對");
} catch (ArithmeticException e) {
System.out.println("算術(shù)異常");
}
}
}
*/
int[] a = new int[2];
Scanner scanner = new Scanner(System.in);
try {
int i = scanner.nextInt();
int j = scanner.nextInt();
a[0] = i;
a[1] = j;
System.out.println(a[0] / a[1]);
} catch (IndexOutOfBoundsException | InputMismatchException | ArithmeticException e) {
System.out.println("其中的一個錯誤");
}
}
}
3
public static void main(String[] args) throws Exception {
/* try {
setSex("afaqfae");
}catch (Exception e) {
System.out.println("上級處理下級拋出的異常");
}*/
setSex("sfwf");
}
public static void setSex (String sex) throws Exception { // 聲明要拋出異常
if ( ! ( sex.equals("男") || sex.equals("女"))) {
System.out.println("發(fā)現(xiàn)了異常情況棒拂,無法處理,交給上級處理");
throw new Exception("發(fā)現(xiàn)了異常情況陨献,無法處理俯艰,交給上級處理"); // 拋出異常 本級函數(shù)不處理異常捡遍,拋出給調(diào)用者
}
}
4
public class SexException extends Exception{
public SexException() {
}
public SexException(String message) {
super(message);
// System.out.println("自定義的異常處理類,抓到了異常竹握,暫時不處理");
}
}
5
public static void main(String[] args) throws Exception {
try {
setSex("afaqfae");
}catch (Exception e) {
System.out.println("上級處理下級拋出的異常");
}
}
public static void setSex (String sex) throws Exception { // 聲明要拋出異常
if ( ! ( sex.equals("男") || sex.equals("女"))) {
// System.out.println("發(fā)現(xiàn)了異常情況遥缕,無法處理彬檀,交給上級處理");
throw new Exception("發(fā)現(xiàn)了異常情況,無法處理,交給上級處理"); // 拋出異常 本級函數(shù)不處理異常玲躯,拋出給調(diào)用者
}
}