java自定义抛出的异常Exception

时间:2022-08-09 15:28:33
package com.zhanzhuang.exception;

public class CustomizeException {
public static void main(String[] args) {
judge();
} public static void judge() {
int a = 2;
int b = 1;
if (a > b) {
try {
throw new MyException("true");
} catch (MyException e) {
e.printStackTrace();
}
} else {
try {
throw new MyException("false");
} catch (MyException e) {
e.printStackTrace();
}
}
}
} class MyException extends Exception { public MyException(String message) {
super(message);
}
}