有没有方法可以访问finally块中的try/catch块中创建的val?或者是最终阻止了范围。在try/catch块中终于“超出范围”
def myTryCatch: Either[Exception, String] = {
try {
val w = runOrFailWithException("Please work...")
Right(w)
} catch {
case ex: Exception => {
Left(ex)
}
}
finally {
// How do I get access to Left or Right in my finally block.
// This does not work
_ match {
case Right(_) =>
case Left(_) =>
}
}
}
你不这样做,最后只能看到东西宣告了try/catch语句范围,而不是内部的它。 – 2012-02-28 13:47:34