Java, Class-specific Exceptions vs. Standard Exceptions

前端 未结 6 1808
北恋
北恋 2021-02-07 12:42

I\'ve been updating an existing library to throw exceptions to help improve debugging by people using the library.

At first, I thought I\'d define exceptions specific to

6条回答
  •  失恋的感觉
    2021-02-07 13:10

    From Effective Java

    You should favor the use of standard exceptions and use the Java platform libraries set of unchecked exceptions that cover what you described. Reusing exceptions has the following benefits :

    Makes your API easier to learn and use because it matches established conventions with which programmers are already familiar

    Fewer Exception classes means a smaller memory footprint and less time spent loading classes.

提交回复
热议问题