我认为主要区别在于它intercept具有一个语义,即您获得的异常是预期的,而不是由程序错误引起的.
所以我通常只intercept在测试用例时才使用它来测试异常,当用户输入错误或类似场景时会正确抛出.
其中一个实际的优点是,它intercept也返回一个Exception,所以你可以这样检查:
intercept[IndexOutOfBoundsException](s charAt -1).getMessage should be === "..."
Run Code Online (Sandbox Code Playgroud)