What is an AssertionError? In which case should I throw it from my own code?

后端 未结 5 1561

In Item 2 of the \"Effective Java, 2nd edition\" book, there is this snippet of code, in which the author wants to forbid the empty initialization of an object.



        
5条回答
  •  庸人自扰
    2020-12-12 20:01

    AssertionError is an Unchecked Exception which rises explicitly by programmer or by API Developer to indicate that assert statement fails.

    assert(x>10);
    

    Output:

    AssertionError
    

    If x is not greater than 10 then you will get runtime exception saying AssertionError.

提交回复
热议问题