I need to call scala code from java, so I need to tell the compiler that a certain method throws certain exceptions. This is easy to do for one exception, but I'm struggling to declare that a method throws multiple exceptions.
This doesn't work:
@throws( classOf[ ExceptionA ], classOf[ExceptionB] )
And, obviously, neither does this:
@throws( classOf[ ExceptionA , ExceptionB] )
In looking at the constructor for
@throws
, it takes a singleClass[_]
argument. Taking that into consideration, you won't be able to use the array notation to represent multiple classes. So the alternative it to add the annotation multiple times, one for each supported exception: