Q:

Scala equivalent of instanceOf Java and exception handling

Just started using Scala for unit testing and am totally confused as to how exceptions are handled in Scala. Below is an example of a JUnit test.
class Test {
  @Test
  void someTest {
    try {
      //Something
    } catch(Exception e) {
      Assert.assertTrue(e.getCause() instanceOf IOException);
    }
  }
} 

Now I want to do the same thing in Scala, I tried
class Test {
  @Test def someTest {
    try {
      //Something
    } catch {
      case e: Exception => assertTrue(e.getCause().isInstanceOf[IOException])
    }
  }
}

But my IDE keeps complaining that Method Apply is not a member of type Any. I read about exception handling in Scala and found that you should use a pattern matcher and that there is no exception handling in Scala. How exactly does this work?

A:

If you are testing scala code I suggest using something more scalish than jUnit like ScalaTest.
import java.io.IOException

import org.scalatest._
import org.scalatest.FlatSpec
import org.scalatest.matchers.ShouldMatchers

object SomeCode
{
    def apply() = {
        throw new IOException
    }
}

class SomeTest
  extends FlatSpec
  with ShouldMatchers
{
    "Something" should "throw an IOException, TODO: why ?" in
    {
        intercept[IOException] {
            SomeCode()
        }
    }

    it should "also throw an IOException here" in
    {
        evaluating { SomeCode() } should produce [IOException]
    }
}

nocolor.run( new SomeTest )

