A
Alper
I have a question about exceptions..
I have this method;
public void calculate(int x) throws IllegalArgumentException {
if(x > 10) throw new IllegalArgumentException("x must be bigger than
10);
//some code here
}
and this one;
public calculate(int x) {
if(x > 10) throw new IllegalArgumentException("x must be bigger than
10);
//some code here
}
What's the purpose of putting "throws IllegalArgumentException" in the
method defination? I mean I run both of them, I couldn't see any
difference.. both gives the same error when I enter argument smaller
than 10. I know it is declaring to the method (which calls calculate())
that it will throw exception.. but it also runs without it.. so why
would I bother putting it?
Thanks for ur answers..
I have this method;
public void calculate(int x) throws IllegalArgumentException {
if(x > 10) throw new IllegalArgumentException("x must be bigger than
10);
//some code here
}
and this one;
public calculate(int x) {
if(x > 10) throw new IllegalArgumentException("x must be bigger than
10);
//some code here
}
What's the purpose of putting "throws IllegalArgumentException" in the
method defination? I mean I run both of them, I couldn't see any
difference.. both gives the same error when I enter argument smaller
than 10. I know it is declaring to the method (which calls calculate())
that it will throw exception.. but it also runs without it.. so why
would I bother putting it?
Thanks for ur answers..