scala,slick:在哪里可以找到给定方法引发的异常?
我想知道在哪里可以找到这样的代码引发的异常:scala,slick:在哪里可以找到给定方法引发的异常?,scala,slick,scaladoc,Scala,Slick,Scaladoc,我想知道在哪里可以找到这样的代码引发的异常: def readFromDB: String = { db_sqlite_xml.withSession { implicit db: Session => xmlQuery.first.text } } 我在光滑的scaladoc()中找不到它;我在javadoc的tableQuery类中搜索了方法“first”,但没有成功 谢谢 奥利维尔 ps:这是我的答案,它起作用了: def read
def readFromDB: String = {
db_sqlite_xml.withSession {
implicit db: Session =>
xmlQuery.first.text
}
}
我在光滑的scaladoc()中找不到它;我在javadoc的tableQuery类中搜索了方法“first”,但没有成功
谢谢
奥利维尔
ps:这是我的答案,它起作用了:
def readFromDB: String = {
db_sqlite_xml.withSession {
implicit db: Session =>
xmlQuery.firstOption.map(u=>u.text).getOrElse("")
}
}
}
感谢您的回答,它帮助了我。该方法属于UnitInvoker的特性,来自: 如果我可以给您一个建议,您应该使用
firstOption
,而不是尝试捕获异常:
final def firstOption()(implicit session: SessionDef): Option[R]
Execute the statement and return the first row of the result set wrapped in Some,
or None if the result set is empty.
通过这种方式,您可以对查询结果进行如下参数匹配:
def readFromDB: String = {
db_sqlite_xml.withSession {
implicit db: Session =>
xmlQuery.firstOption match {
case Some(value) => value.text
case _ => // handle no result
}
}
}
def readFromDB: String = {
db_sqlite_xml.withSession {
implicit db: Session =>
xmlQuery.firstOption match {
case Some(value) => value.text
case _ => // handle no result
}
}
}