class SelfException extends Exception //自定义异常,可以用于包装异常等,做异常链
{
public SelfException(){}
public SelfException(String msg)
{
super(msg);
}
}
public class Main {
static void throwException() throws SelfException
{
throw new SelfException("selfException");
}
public static void main(String[] args) throws Exception {
try
{
throwException();
}
catch (SelfException e)
{
e.printStackTrace();
throw new Exception(e); //再抛异常
}
finally
{
System.out.println("finally");
}
}
}
Java -- 异常处理
最新推荐文章于 2023-11-09 23:22:07 发布