解决方法
例外翻译:
最好不要使用对最终用户没有意义的消息来污染您的应用程序,而是创建有意义的异常和消息,这些异常和消息将转换在应用程序实现深处发生的异常/错误.
根据@ Romain的评论,您可以使用Exception(Throwable cause)构造函数来跟踪较低级别的异常.
从Effective Java第2版,第61项:
[…] higher layers should catch
lower-level exceptions and,in their
place,throw exceptions that can be
explained in terms of the higher-level
abstraction. This idiom is known as
exception translation:
// Exception Translation try { // Use lower-level abstraction to do our bidding ... } catch(LowerLevelException e) { throw new HigherLevelException(...); }