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

posted @ 2013-10-31 20:13  今晚打酱油_  阅读(139)  评论(0编辑  收藏  举报