MySQLSyntaxErrorException
Slick/MySQL は、構文が正しくない場合やCommunicationsException
、データベースに到達できない場合にスローします。
これらのタイプの例外の両方をキャッチする簡単な例を次に示します。
try {
Database.forURL("jdbc:mysql://some-host:3306/db-name",
driver = "com.mysql.jdbc.Driver",
user="",
password="") withSession { session: Session =>
implicit val s = session
...
}
} catch {
case e: MySQLSyntaxErrorException =>
... handle the syntax error ...
// You may want to define your own Exception that wraps the MySQL one
// and adds more context
case e: CommunicationsException =>
... handle the connection error ...
}
次に、webapp コードでカスタム例外をキャッチし (コード内のコメントを参照)、それに応じて HTTP コードを返します。