Skip to content

Instantly share code, notes, and snippets.

@msimav
Last active July 29, 2016 11:05
Show Gist options
  • Select an option

  • Save msimav/cff8294be6846619aaedd449a3074086 to your computer and use it in GitHub Desktop.

Select an option

Save msimav/cff8294be6846619aaedd449a3074086 to your computer and use it in GitHub Desktop.
Simple helper to run code in try catch and wrap it with Either
@inline def Safely[T](block: => T): Either[Exception, T] =
try {
Right(block)
} catch {
case e: Exception => Left(e)
}
object Example {
val result = Safely {
"15".toInt
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment