-
throwing Exception
I want to throw exception manually. I tried the following but it fails.
Code:
throw java.lang.ArrayIndexOutOfBoundsException;
I get following exception:
Code:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
java.lang.ArrayIndexOutOfBoundsException cannot be resolved
Please advice.
-
What does your method signature look like?
-
Code:
public void calculateSum()
{
...
}
Actually method has nothing to do with this. I want to know, can I raise an exception myself?
-
Yes. You just have to put 'throws whateverException' on the end of your signature.
Code:
public void calculateSum() throws InvalidSumException{
}