What's the intended use of IllegalStateException?

前端 未结 6 945
别跟我提以往
别跟我提以往 2020-12-07 14:47

This came up in a discussion with a colleague today.

The Javadocs for Java\'s IllegalStateException state that it:

Signals that a method has b

6条回答
  •  猫巷女王i
    2020-12-07 15:05

    Given a library, it should throw an IllegalStateException or IllegalArgumentException whenever it detects a bug due to the user code, whereas the library should throw an AssertionError whenever it detects a bug due to the library's own implementation.

    For example, in the library's tests, you may expect the library throws an IllegalStateException when the order of method calls are wrong. But you will never expect the library throws an AssertionError.

提交回复
热议问题