How to throw an Exception when your method signature doesn't allow to throw Exception?

Viewed 7386

I have a method like this:

public void getSomething(){
...
}

I want to throw an Exception inside getSomething(). The compiler will not allow me to do that because my method doesn't allow Exception to be thrown in there. But I need to throw a subclass of Exception for my testing (I can't throw Unchecked Exception). This is clearly a hack but I need it for my testing. I tried EasyMock but it doesn't allow me to do that either. Any ideas how to do that?

Thanks, Sean Nguyen

3 Answers
Related