when declaring a methods with “IllegalAccessException” eclipse forces me to
declare the method as throwing an exception
public void a() throws IllegalAccessException {
if(x == 1){
throw new IllegalAccessException("TEST);
}
}
and in method b that uses “IllegalStateException” i dont need to declare the method as throw an exception
public void b() {
if(x == 1){
throw new IllegalStateException("TEST);
}
}
what is the different between thous exception
that one forces me tho declare the method that throw an exception
and the other is not
thank you
Because
IllegalAccessExceptionis notRuntimeException(i.e. is checked exception) andIllegalStateExceptionis aRuntimeException(i.e. is unchecked exception).Read this for more information: Difference between java.lang.RuntimeException and java.lang.Exception
And this explanation on Oracle site: http://download.oracle.com/javase/tutorial/essential/exceptions/catchOrDeclare.html