title: Better Exception Handling in JPA
body: <p>I used EJB3/JPA when persisting my entities and I am happy on how it is able to manage my DB related
  task.
  My only concern is on the exception handling.  My sample code when saving entity always comes in this flavor.
  Most of the tutorials that I read on the net comes in this flavor also with no regards to exception handling.</p>
  
  <pre><code>@Stateless
  public class StudentFacade{
      @PersistenceContext(unitName = "MyDBPU")
      private EntityManager em;
  
      public void save(Student student) {
          em.persist(student);
      }
  }
  </code></pre>
  
  <p>But I dont know whats the best way of exception handling in an EJB app?
  What should be the best way when handling exception?</p>
  
  <p>Is this how others is handling the exception? A try catch block on your session facade?</p>
  
  <pre><code>@Stateless
  public class StudentFacade{
      @PersistenceContext(unitName = "MyDBPU")
      private EntityManager em;
  
      public void save(Student student) {
          try {
              em.persist(student);
          } catch(Exception e) {
              //log it or do something
          }
      }
  }
  </code></pre>
  
  <p>or letting the method throw an exception?</p>
  
  <pre><code>public void save(Student student) throws Exception {
      em.persist(student);
  }
  </code></pre>
  
  <p>I dont know if  my understanding is correct since I am still learning EJB.
  Thanks</p>