Checked vs Unchecked Exceptions (Cont.)


Unchecked Exceptions
Unchecked exceptions are not checked at compiling time.
  • In C++, all exceptions are unchecked, so it is not forced by the compiler to either handle or specify the exception. It is up to the programmers to be civilized, and specify or catch the exceptions.

Consider the following Java program. It compiles well, but it throws ArithmeticException when run. The compiler allows it to compile, because ArithmeticException is an unchecked exception.

DivideByZero.java (unchecked ArithmeticException exception)
class DivideByZero { 
  public static void main( String args[ ] ) { 
    int x = Integer.parseInt( args[0] ); 
    int y = Integer.parseInt( args[1] ); 
    System.out.println( x / y );
  }
}
shell> java DivideByZero  (integer)   (integer)        

Two comments:


      A fool and his money are easily parted.