# 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("除数不能为0");
} finally {
// 资源的释放
System.out.println("必须要执行的步骤,一定会执行");
}
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("数据格式不对");
} catch (ArithmeticException e) {
System.out.println("算术异常");
}
}
}
*/
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("发现了异常情况,无法处理,交给上级处理");
throw new Exception("发现了异常情况,无法处理,交给上级处理"); // 抛出异常 本级函数不处理异常,抛出给调用者
}
}
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("发现了异常情况,无法处理,交给上级处理");
throw new Exception("发现了异常情况,无法处理,交给上级处理"); // 抛出异常 本级函数不处理异常,抛出给调用者
}
}