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.