Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Example to show Argument Exception in java 
 

Here we are describing the use of using Argument exception in java .Exceptions are the way in Java to indicate to a calling method that an abnormal condition has occurred.

 

Example to show Argument Exception in java

                         

In this Tutorial  we explain an example from Argument exception in java .Exceptions are the condition  in Java to indicate a calling method that an abnormal condition has occurred. This tutorial describes  how to handle Argument exceptions appropriately in your programs. The steps involved in the program are described below:-

private static Scanner key = new Scanner(System.in):-Here we are declaring Scanner class object. Scanner is a class which is used to parse primitive types and strings using regular expressions.

Input = key. next():-This is the method by which we can find and returns the next complete token from this scanner.

System.out.println(Input + " is not an Integer value" + "\n"+ "Please enter appropriate value"):-This is the Exception message which is to be displayed if the number you entered is not a real number.

ArgumentException.java


import java.util.*;

public class ArgumentException {

    private static Scanner key = new Scanner(System.in);

    public static void main(String args[]) {
        int index;
        int i;
        String Input;

        for (index = 0; index < args.length; index++) {
        }

        System.out.print("Please enter a real number : ");
        Input = key.next();
        try {
            i = Integer.parseInt(Input);
            System.out.println("The value is " + i);
        catch (NumberFormatException e) {
            System.out.println(Input + " is not an Integer value" "\n" 
                    "Please enter apporipriate value");
        }
    }
}

Output of the program

Please enter a real number : Girish
Girish is not an Integer value
Please enter apporipriate value

Download sourecode

 

                         

» View all related tutorials
Related Tags: c exception io stack type exec uri lock this block exe row handle program to execution ram each pos ast

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.