注意异常丢失的情况-仰望者-iteye技术网站
2011年09月01日
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.catchEx ception(UserDefineException.java:17)
at com.lwf.thinking.eight.UserDefineException.main(Us erDefineException.java:12)
从结果可以发现EusBusiException异常丢失了。这是JAVA的一个重要的缺陷。。
2011年09月01日
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.catchEx ception(UserDefineException.java:17)
at com.lwf.thinking.eight.UserDefineException.main(Us erDefineException.java:12)
从结果可以发现EusBusiException异常丢失了。这是JAVA的一个重要的缺陷。。
本文详细解析了一段Java代码中关于自定义异常类的使用,指出在异常处理过程中可能出现的异常丢失问题,并通过实例代码展示了解决方案。
641

被折叠的 条评论
为什么被折叠?



