Skip to content

Instantly share code, notes, and snippets.

@yuroyoro
Created May 21, 2010 08:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuroyoro/408612 to your computer and use it in GitHub Desktop.
Save yuroyoro/408612 to your computer and use it in GitHub Desktop.
def tryo[T]( f: => T )
( implicit onError: Throwable => Option[T] =
{ t:Throwable => None }): Option[T] =
{
try {
Some( f )
} catch {
case c => onError( c )
}
}
def trye[T]( f: => T )
( implicit onError: Throwable => Either[Throwable,T] =
{ t:Throwable => Left( t ) }): Either[Throwable,T] =
{
try{
Right( f )
} catch {
case c => onError( c )
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment