zoukankan      html  css  js  c++  java
  • Effective Java 60 Favor the use of standard exceptions

    Benefits to reuse preexisting exceptions

    1. It makes your API easier to learn and use.
    2. Programs using your API are easier to read.
    3. Fewer exception classes mean a smaller memory footprint and less time spent loading classes.

    Common Exceptions

    Exception

    Occasion for Use

    IllegalArgumentException

    Non-null parameter value is inappropriate

    IllegalStateException

    Object state is inappropriate for method invocation

    NullPointerException

    Parameter value is null where prohibited

    IndexOutOfBoundsException

    Index parameter value is out of range

    ConcurrentModificationException

    Concurrent modification of an object has been detected where it is prohibited

    UnsupportedOperationException

    Object does not support method

    Principle

    1. Reuse must be based on semantics, not just on name.
    2. Also, feel free to subclass an existing exception if you want to add a bit more failure-capture information (Item 63).

       

  • 相关阅读:
    C++中的ravalue学习笔记
    C++中的抽象类
    C++中的显式类型转换
    C++中的继承和多继承
    C++中的多态
    Yocto学习笔记
    HIDL学习笔记
    hadoop2.5搭建过程
    《Redis设计与实现》学习笔记
    40 数组中只出现一次的数字
  • 原文地址:https://www.cnblogs.com/haokaibo/p/favor-the-use-of-standard-exceptions.html
Copyright © 2011-2022 走看看