注意异常丢失的情况

package com.lwf.thinking.eight;
import java.sql.SQLException;
public class UserDefineException {
	public static void main(String[] args) throws Exception{
		UserDefineException u = new UserDefineException();
		try {
			u.throwException();
		} finally{
			u.catchException();
		}
	}
	
	public static void catchException() throws EusException{
		throw new EusException();
	}
	public static void throwException() throws EusBusiException {
		throw new EusBusiException();
	}
} 
 

对应的异常类EusException和EusBusiException都只是简单的继承Exception类。

输出结果:

Exception in thread "main" com.lwf.thinking.eight.EusException
    at com.lwf.thinking.eight.UserDefineException.catchException(UserDefineException.java:17)
    at com.lwf.thinking.eight.UserDefineException.main(UserDefineException.java:12)
从结果可以发现EusBusiException异常丢失了。这是JAVA的一个重要的缺陷。。

你可能感兴趣的:(java,thread,sql)