Catch Unique Key Exception Scala Slick
问题 Below is the code I use in inserting into the db however when the name of a group which is unique is entered I get a unique key violation in the logs override def create(groups: GroupEntity): Future[GroupEntity] = db.run{groupsTableQuery returning groupsTableQuery += groups} 回答1: Recover using recoverWith . As all exceptions will be of type PSQLException, check if certain keywords exist in message of the exception to handle it. val future = db.run { groupsTableQuery returning groupsTableQuery