2

I was reading about exceptions in java

and i came across this

Checked exceptions are subject to the Catch or Specify Requirement. All exceptions are checked exceptions, except for those indicated by Error, RuntimeException, and their subclasses.

Which i don't understand. Could someone please tell me what it means ?

jmj
  • 237,923
  • 42
  • 401
  • 438
user574183
  • 710
  • 1
  • 10
  • 22

1 Answers1

4

Checked exceptions are subject to the Catch or Specify Requirement. All exceptions are checked exceptions, except for those indicated by Error, RuntimeException, and their subclasses.

It says all the exceptions needs to be handled either by catching them

try{
  call();
}catch(SomeException ex){
 //handling
}

or by throwing back

public void caller() throws SomeException{ call(); }

call(); method is declared to throw SomeException

public void caller(){ call(); }

This will not compile,

There are RuntimeException which are unchecked, you don't need to handle them, they are mainly unexpected ones (some of them are errors) so we don't have to forcibly handle them


See Also

Community
  • 1
  • 1
jmj
  • 237,923
  • 42
  • 401
  • 438