title: What is an AssertionError? In which case should I throw it from my own code?
body: <p>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.</p>
  
  <pre><code>class Example {
      private Example() {
          throw new AssertionError();
      }
  }
  </code></pre>
  
  <p>The type of exception thrown, is what confuses me here.</p>
  
  <p>I don't understand if the <code>AssertionError</code> is thrown just because of an absence of more suited errors or because it should be this way.</p>
  
  <p>As I understand, this error is thrown by the framework when an <code>assert</code> statement fails. Also, in the javadoc it's just written</p>
  
  <blockquote>
    <p>[An AssertionError is] Thrown to indicate that an assertion has failed.</p>
  </blockquote>
  
  <p>But I don't see any assertion (true-false statement) being violated here.
  Of course the "You shall not instantiate an item of this class" statement has been violated, but if this is the logic behind that, then we should all throw <code>AssertionError</code>s everywhere, and that is obviously not what happens.</p>
  
  <p>FWIW, I'd have just thrown a</p>
  
  <pre><code>new IllegalStateException("Must not instantiate an element of this class")
  </code></pre>
  
  <p>Is there something wrong with that? In which case should I throw an <code>AssertionError</code> in my own code?</p>
  
  <p>Sorry if it's just a subtle doubt but I use this pattern a lot in my code and I want to make sure I'm doing the right thing.</p>