Java – intercept exceptions

I want to use custom exceptions so that a user - friendly message appears when any sort exception occurs

What is the direct way to do this? Should I take additional precautions to avoid interfering with swing's EDT?

Solution

Exception translation:

It is best not to pollute your application with messages that are meaningless to the end user, but to create meaningful exceptions and messages that will transform the exceptions / errors that occur deep in the application implementation

According to @ Romain's comments, you can use the exception (throwable cause) constructor to track lower level exceptions

From effective java version 2, item 61:

// Exception Translation
    try {
         // Use lower-level abstraction to do our bidding
         ...
    } catch(LowerLevelException e) {
         throw new HigherLevelException(...);
    }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>