JAVA中的自定义异常,其实只要直接或者间接的继承异常的父类Exception就可以了。
package com.exception;
public class MyException extends Exception
{
public MyException(String message)
{
super(message);
}
}
package com.exception;
public class ExceptionTest
{
public void method(String str) throws MyException
{
if(null == str){
throw new MyException("传入的字符串参数不能为空!!");
}
else{
System.out.println(str);
}
}
public static void main(String[] args) throws MyException
{
ExceptionTest test = new ExceptionTest();
test.method(null);
}
}