开发者

what does the following mean "checked JMSException converted to unchecked"

Can some checked exceptions be c开发者_Go百科onverted to unchecked exceptions.

When I read the docs from jms, I found some method convert checked exceptions into unchecked. I do not need to use "throws" anymore. Is this a feature of Java?


You can also convert yourself exceptions from checked to unchecked:

try {
    ...
} catch (CheckedException ex) {
    throw new UncheckedException(ex);
}

where the fictional class CheckedException is the checked excetion that is thrown by the code within the dots, and UncheckedException extends RuntimeException or one of its descendants.

Without going into the checked vs unchecked exception debate, I would like to point out that is a good practice to convert exception as you go up with your abstraction layers, also your exception should be less specific about the implementation details.

For instance, if I've an interface PDFDocument with a method save(), it shouldn't throw an IOException, because you could have an implementation saving to database, another to filesystem and a third saving to a remote site. Instead you could create your own exceptions or use one of the standard ones if it fits.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜