adsense


Showing posts with label JAVA EXAMPLES PASS ARGUMENT WHILE THROWING AN EXCEPTION. Show all posts
Showing posts with label JAVA EXAMPLES PASS ARGUMENT WHILE THROWING AN EXCEPTION. Show all posts

Thursday, 29 October 2015

JAVA EXAMPLES PASS ARGUMENT WHILE THROWING AN EXCEPTION PAGE 132

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button



JAVA EXAMPLES PASS ARGUMENT WHILE THROWING AN EXCEPTION






Java Examples - Pass argument while throwing an Exception


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