Results 1 to 2 of 2

Thread: Catch string value error

  1. #1
    Junior Member
    Join Date
    Sep 2007
    Answers
    1

    Catch string value error

    How can I give the exception method if I entered a string value for a integer value? I mean the user asking to enter a integer value. But user entered a string value. How should I catch this error using exception? Can you give some examples?


  2. #2
    Junior Member
    Join Date
    Sep 2007
    Answers
    8

    Smile Re: Catch string value error

    Hi

    Use Integer.parseInt(String obj) method.
    If it gives exception in parsing,then u can catch it and give a message to the user about invalid data..

    for example:
    if user entered is "hello" instead of 56.

    String val="hello".

    int i=Integer.parseInt(val);

    Regards,
    Raghu


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact