Skip to content

Instantly share code, notes, and snippets.

@carey
Created April 3, 2013 00:28
Show Gist options
  • Save carey/5297461 to your computer and use it in GitHub Desktop.
Save carey/5297461 to your computer and use it in GitHub Desktop.
Assert that a code block throws an exception or a subclass in Scala.
def assertThrows[A <: Throwable: ClassTag](fn: => Unit) {
val ct = classTag[A]
try {
fn
fail("Expected " + ct)
} catch {
case ct(e: Throwable) => // ok
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment