Java Examples - Runtime Exceptions

Advertisements


Problem Description:

How to handle runtime exceptions?

Solution:

This example shows how to handle the runtime exception in a java programs.

public class NeverCaught {
   static void f() {
      throw new RuntimeException("From f()");
   }
   static void g() {
      f();
   }
   public static void main(String[] args) {
      g();
   }
}

Result:

The above code sample will produce the following result.

From f()


Advertisements
Advertisements