A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/javaexamples/exception_getmessage.htm below:

How to pass arguments while throwing checked exception in Java

How to pass arguments while throwing checked exception in Java Problem Description

How to pass arguments while throwing checked exception?

Solution

This example shows how to pass arguments while throwing an exception & how to use these arguments while catching an exception using getMessage() method of Exception class.

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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4