Skip to content

Java Exceptions#

Checked And Unchecked Exception In Java#

  • There are 2 types of exception in java: checked and unchecked. All checked exception class are inherited from Exception class except RuntimeException. RuntimeException is the base class of all unchecked exception class, that is also a signal to recognize which one is checked exception or unchecked exception.  #zoom
  • The difference between checked and unchecked exception classes is the time to identify the exception can happen. With checked exception, checking is happened in compile time, some IDE will help us by showing syntax errors if we use a method that can throw any checked exception without try/catch. We have some checked exception: IOException, Interrupted Exception, XMLParseException... With unchecked Exception, checking exception can happen or not is only happened in the Runtime time and IDE will not help us identify it. Some popular unchecked exception: NullPointerException, IndexOutOfBoundException, ClassCastException...
  • So, in programming the unchecked exception can be thrown in cases program have errors with logic. For errors that can be handle, the checked exception should be thrown.

See Also#