package com.bwie.test;
/*
* 自定义异常 必须继承Exception 或者其子类
* */
public class MyException extends Exception {
public MyException(String message) {
super(message);
}
public MyException(){
}
//测试方法
public static void main(String[] args) {
MyException test=new MyException();
try{
test.createDoubleArray(-10);
}catch(MyException ex){
ex.printStackTrace();
}
}
//自定义异常方法
public double[] createDoubleArray(int length)throws MyException{
if(length<0){
throw new MyException("数组的长度不能小于0");
}
return new double[length];
}
}
异常的概念和Java异常体系结构:https://blog.csdn.net/JV_Kevin/article/details/89011703