When to use custom exceptions vs. existing exceptions vs. generic exceptions

后端 未结 5 2078
遥遥无期
遥遥无期 2020-12-14 04:05

I\'m trying to figure out what the correct form of exceptions to throw would be for a library I am writing. One example of what I need to handle is logging a user in to a st

5条回答
  •  抹茶落季
    2020-12-14 04:38

    You can nearly never go wrong by having fine-grained exception classes that extend a common base class. That way, callers who need to specifically catch some and let others through can, and callers who want to treat them all together can do so.

提交回复
热议问题