Should I declare unchecked exceptions in the throws specification?

前端 未结 3 1994
粉色の甜心
粉色の甜心 2021-01-31 09:13

I\'m aware checked exceptions have to be handled or specified, but unchecked exceptions are optional.

If for some reason I can reasonably expect an unchecked exception t

3条回答
  •  孤独总比滥情好
    2021-01-31 09:41

    That is a design decision. Normally you wouldn't do that. But if you think it is crucial for the user of your code to catch an Exception, then it is a way to hint him doing that. Another way would be to just add it to the documentation, and explain why it is important to catch the Exception.

提交回复
热议问题