title: How to check which exception type was thrown in Java?
body: <p>How can I determine which type of exception was caught, if an operation catches multiple exceptions?</p>
  
  <p>This example should make more sense:</p>
  
  <pre><code>try {
    int x = doSomething();
  } catch (NotAnInt | ParseError e) {
    if (/* thrown error is NotAnInt */) {    // line 5
      // printSomething
    } else {
      // print something else
    }
  }
  </code></pre>
  
  <p>On line 5, how can I check which exception was caught?</p>
  
  <p>I tried <code>if (e.equals(NotAnInt.class)) {..}</code> but no luck.</p>
  
  <p>NOTE: <code>NotAnInt</code> and <code>ParseError</code> are classes in my project that extend <code>Exception</code>.</p>