Java Examples - Handle Checked Exception


Advertisements


Problem Description

How to handle checked exception ?

Solution

This example shows how to handle checked exception using catch block.

public class Main {
   public static void main (String args[]) {
      try {
         throw new Exception("throwing an exception");
      } catch (Exception e) {
         System.out.println(e.getMessage());
      }
   }
}

Result

The above code sample will produce the following result.

throwing an exception

java_exceptions.htm

Advertisements