Java -- 异常处理

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

原文地址:https://www.cnblogs.com/xj626852095/p/3648074.html