Last active
July 29, 2016 11:05
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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