How to convert exception catching code from java to scala using intercept ?
From reading http://www.scalatest.org/getting_started_with_fun_suite it seems to be recommended to use intercept when catching exceptions. In the exception catching code below I need to access the Exception type so as to check its type within the
assert :
catch {
case me : MyException => {
assert(me.getDetail.getClass() === classOf[GenericException]);
}
}
This does not seem to be possible using intercept as below code causes a compiler error : ‘forward reference extends over definition of value exception’
Here is the converted to scala catch block :
val exception = intercept[MyException] {
assert(exception.getDetail.getClass() === classOf[GenericException]);
}
The error occurs on line
assert(exception.getDetail.getClass() === classOf[GenericException]);
Well your definition of
exceptionis circular. What you want is: