title: How to catch slick postgres exceptions for duplicate key value violations
body: <p>My table has a unique index on a pair of columns in my postgresql database.</p>
  
  <p>I want to know how I can catch a duplicate key exception when I am inserting:</p>
  
  <pre><code>def save(user: User)(implicit session: Session): User = {
    val newId = (users returning users.map(_id) += user
    user.copy(id = newId)
  }
  </code></pre>
  
  <p>My logs show this exception:</p>
  
  <pre><code>Execution exception[[PSQLException: ERROR: duplicate key value violates unique constraint "...."
  </code></pre>
  
  <p>I haven't really used exceptions much in scala either yet also.</p>