java自定义抛出的异常Exception

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);
    }
}

猜你喜欢

转载自www.cnblogs.com/zhanzhuang/p/9878245.html