看下面的代码片段:
userService.insert(user) match {
case Success(f) => Logger.debug("User created successfully")
case Failure(e) => {
// how do I determine the type of `e`?
}
}
如何确定
Failure
包含的异常类型?我需要根据异常类型采取不同的措施。
最佳答案
case Success(f) =>
case Failure(e: ExceptionType1) =>
case Failure(e: ExceptionType2) =>
case Failure(e) => // other
或者
case Success(f) =>
case Failure(e) => e match {
case e1: ExceptionType1 =>
case e2: ExceptioNType2 =>
case _ =>
}
关于Scala:如何确定故障的异常类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20940558/