We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I was hunting for idiomatic approaches to logging exceptions with scala-logging. I was impressed with the Try approach described at the end of this answer.
object ExceptionExample extends LazyLogging { def main(args:Array[String]):Unit = { val maybeResult = Try[Int] { "aa".toInt } match { case failure @ Failure(throwable) => throwable match { case _:ArithmeticException => Success(-1) // Recover from e.g., 1/0 case runtimeException: RuntimeException => // Log RuntimeExceptions logger.error("ExceptionMsg", runtimeException); failure } case success @ _ => success } println("Getting result"); val result = maybeResult.get // Will Rethrow on Failure println("result = " + result.toString); } }
Is there an approach with less boilerplate?
The text was updated successfully, but these errors were encountered:
No branches or pull requests
I was hunting for idiomatic approaches to logging exceptions with scala-logging. I was impressed with the Try approach described at the end of this answer.
Is there an approach with less boilerplate?
The text was updated successfully, but these errors were encountered: