Discuss / Java / 自定义异常

自定义异常

Topic source

#1 Created at ... [Delete] [Delete and Lock User]
public class Main {    public static void main(String[] args) {        try {            System.out.println(Tro(-5));        } catch (Exception e) {            System.out.println("catched");            throw new AbcException(e);        }    }    public static int Tro(int a){        if(a<0){            throw new AbcException("参数为负");        }        return a;    }}class BaseException extends RuntimeException {        public BaseException(){        }        public BaseException(String Message){        super(Message);        }        public BaseException(String Message,Throwable cause){        super(Message,cause);        }        public BaseException(Throwable cause){        super(cause);        }        }class AbcException extends BaseException{    public AbcException(){    }    public AbcException(String Message){        super(Message);    }    public AbcException(String Message,Throwable cause){        super(Message,cause);    }    public AbcException(Throwable cause){        super(cause);    }}

#2 Created at ... [Delete] [Delete and Lock User]
public class Main {
    public static void main(String[] args) {
        try {
            System.out.println(Tro(-5));        } catch (Exception e) {
            System.out.println("catched");            throw new AbcException(e);        }
    }

    public static int Tro(int a){
        if(a<0){
            throw new AbcException("参数为负");        }
        return a;    }
}

class BaseException extends RuntimeException {
        public BaseException(){
        }
        public BaseException(String Message){
        super(Message);        }
        public BaseException(String Message,Throwable cause){
        super(Message,cause);        }
        public BaseException(Throwable cause){
        super(cause);        }


        }
class AbcException extends BaseException{
    public AbcException(){
    }
    public AbcException(String Message){
        super(Message);    }
    public AbcException(String Message,Throwable cause){
        super(Message,cause);    }
    public AbcException(Throwable cause){
        super(cause);    }
}

  • 1

Reply