Review (from CS 170):   exception handling

  • Error reporting in Java is by "throwing" exceptions

  • How to handle exceptions in Java

       try
       {
           // block of code that may throw exception
       }
       catch (Exception e)
       {
           // block of code that deal with exception
       }

  • Unhandled exceptions will cause the Java program to terminate

  • Why do we discuss exception here ?

    • Java has an exception hierarchy that is similar to the class hierarchy