preserve IOException type when translating exceptions. fixes #253

This commit is contained in:
Mark Harrah 2011-11-04 13:11:10 -04:00
parent 8beb823a9b
commit 30bdcf68d4
1 changed files with 7 additions and 3 deletions

View File

@ -7,7 +7,10 @@ object ErrorHandling
{ {
def translate[T](msg: => String)(f: => T) = def translate[T](msg: => String)(f: => T) =
try { f } try { f }
catch { case e: Exception => throw new TranslatedException(msg + e.toString, e) } catch {
case e: IOException => throw new TranslatedIOException(msg + e.toString, e)
case e: Exception => throw new TranslatedException(msg + e.toString, e)
}
def wideConvert[T](f: => T): Either[Throwable, T] = def wideConvert[T](f: => T): Either[Throwable, T] =
try { Right(f) } try { Right(f) }
@ -31,7 +34,8 @@ object ErrorHandling
else else
e.toString e.toString
} }
final class TranslatedException private[sbt](msg: String, cause: Throwable) extends RuntimeException(msg, cause) sealed class TranslatedException private[sbt](msg: String, cause: Throwable) extends RuntimeException(msg, cause)
{ {
override def toString = msg override def toString = msg
} }
final class TranslatedIOException private[sbt](msg: String, cause: IOException) extends TranslatedException(msg, cause)