Results 1 to 3 of 3
  1. #1
    Moedig is offline Member
    Join Date
    Oct 2011
    Posts
    5
    Rep Power
    0

    Default Exception handling

    Hi guys, Basically i just wondered if someone could explain to me how it is possible to return to the start of the try block after an exception has been caught.
    I have

    try{
    //method for user input
    }
    catch (exception definition) {
    //exception message when user inputs wrong type of data etc
    }

    but id like it to return to the start of the try block to allow the user to re-enter the correct data... is this possible? please help,

    greatly appreciated,
    Moedig

  2. #2
    Shoss's Avatar
    Shoss is offline Member
    Join Date
    Feb 2011
    Posts
    94
    Rep Power
    0

    Default Re: Exception handling

    There isn't a way to jump back up to a certain line of code. You'll need to use functions or loops to achieve what you want.

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,788
    Rep Power
    7

    Default Re: Exception handling

    Example using a loop:
    Java Code:
    declare a boolean
    while input is invalid {
        try {
            get user input which might throw exception
            flag input as valid
        } catch exception {
            display error message
        }
    }
    If the user input throws an exception then it will jump the line which marks the input as valid. Then it will go around the loop again.

Similar Threads

  1. exception handling
    By niksipandit in forum New To Java
    Replies: 3
    Last Post: 09-22-2011, 02:25 PM
  2. Exception handling
    By herat in forum New To Java
    Replies: 1
    Last Post: 06-21-2011, 10:13 AM
  3. Exception Handling
    By eLancaster in forum New To Java
    Replies: 4
    Last Post: 02-20-2011, 12:00 AM
  4. Exception Handling
    By liljester in forum New To Java
    Replies: 4
    Last Post: 06-21-2010, 03:09 PM
  5. Exception Handling help
    By MZA in forum New To Java
    Replies: 3
    Last Post: 02-10-2010, 09:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •