What's the intended use of IllegalStateException?

前端 未结 6 944
别跟我提以往
别跟我提以往 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条回答
  •  臣服心动
    2020-12-07 15:14

    I ran into this with:

    try {
        MessageDigest digest = MessageDigest.getInstance("SHA-1");
        ...
    } catch (NoSuchAlgorithmException e) {
        throw new AssertionError(e);
    }
    

    I think it will be impractical for me to throw IllegalStateException here in place of AssertionException even though this falls into the "the Java environment" category.

提交回复
热议问题