exception handeling to check type

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tolkienarda
    Contributor
    • Dec 2006
    • 316

    #1

    exception handeling to check type

    hello wonderful people of java land

    i am writing a program and trying to check to make sure some of my inputs are valid integers. i was told that i needed to read into exception handeling and now that i have done so i think i know what i have to do but i would just like to check with some of you experts and make sure i am going to do the right thing
    pesudo code:

    try block
    -get inputs from user
    -store inputs into a type int

    catch - if exception is thrown for a not valid conversion
    -output to user that the input was not valid
    -re attempt input //QUESTION here how do i go back to the catch block can i
    have this in a loop or somthing

    finally
    -do the stuff i needed to do with the ints


    thanks
    eric
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by tolkienarda
    hello wonderful people of java land

    i am writing a program and trying to check to make sure some of my inputs are valid integers. i was told that i needed to read into exception handeling and now that i have done so i think i know what i have to do but i would just like to check with some of you experts and make sure i am going to do the right thing
    pesudo code:

    try block
    -get inputs from user
    -store inputs into a type int

    catch - if exception is thrown for a not valid conversion
    -output to user that the input was not valid
    -re attempt input //QUESTION here how do i go back to the catch block can i
    have this in a loop or somthing

    finally
    -do the stuff i needed to do with the ints


    thanks
    eric
    Yes you can use a while to loop until the user puts in valid input.
    The "-do the stuff i needed to do with the ints" part should be done in the try block as well. The finally block is not for doing the actual processing.

    Comment

    Working...