title: Can not catch runtime exception thrown by EntityManager.persist
body: <p>I have a stateless session bean called DatabaseService, here is code:</p>
  
  <pre><code>public void create(T entity) {
      try {
          getEntityManager().persist(entity);
      } catch (Exception e) {
          System.out.println("handle runtime exception here: " + e.getClass().getName());
      }
  }
  </code></pre>
  
  <p>But the code in catch block never get executed, why is that?</p>
  
  <p>If i modify code like this then catch block will works:</p>
  
  <pre><code>public void create(T entity) {
      try {
          throw new RuntimeException();
      } catch (Exception e) {
          System.out.println("handle runtime exception here: " + e.getClass().getName());
      }
  }
  </code></pre>