Mailing List ArchiveSupport open source code!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: java question
- To: tlug@example.com
- Subject: Re: java question
- From: James Gibson <twistedhammer@example.com>
- Date: Wed, 13 Jun 2001 18:58:28 -0400
- Content-Transfer-Encoding: 8bit
- Content-Type: text/plain
- In-Reply-To: <3B27D7D1.BA57DEA5@example.com>
- References: <3B278493.388731B4@example.com> <3B27D7D1.BA57DEA5@example.com>
- Reply-To: James Gibson <twistedhammer@example.com>
- Resent-From: tlug@example.com
- Resent-Message-ID: <nWvCD.A.zwG.B--J7@example.com>
- Resent-Sender: tlug-request@example.com
- Sender: twistedhammer@example.com
- User-Agent: IMP/PHP3 Imap webMail Program 2.0.11
Quoting Fredric Fredricson <fredric.fredriksson@example.com>: > B0Ti wrote: > > > > Evening, > > > > Maybe it's trivial, but I cannot find a clean solution to this. > > I need to read in an integer and it must be within a limit. Something > > like this: > > > > try { > > int someInt = Integer.parseInt(readUserInput()); > > if (someInt > 10 || someInt < 0) throw new NumberFormatException; > > } > > catch (NumberFormatException) { /* goto begin :( ...*/ } > > > > My problem is that when NumberFormatException is caught I need to go > > back (restart at try) and read in the integer again. > > Having grown up on basic I would immediately use a goto statement if > > java would allow it. > > How should this be done cleanly and effectively? > > Just a small observation: just because java has exceptions does not > mean that they are good for everything. Maybe a solution without > exceptions would be cleaner in this particular case. > > /Fredric Fredricson Been too long since I've used java to give you particulars... however, here's the basic idea for something like this using C style psuedo-code, and no exception handling... while(TRUE) { #loop endlessly someInt = readUserInput(); #get input if (isLegal(someInt)) { #if input is legal break; #then exit.loop } #otherwise, } #start over Also, if GOTO is still a gut reaction, you might want to read up some more on C-style looping mechanisms such as this. James Gibson twistedhammer@example.com -------------------------------------- FREE ANONYMOUS EMAIL! Sign up now. http://www.subdimension.com/freemail
- References:
- java question
- From: B0Ti <9915104t@example.com>
- Re: java question
- From: Fredric Fredricson <fredric.fredriksson@example.com>
Home | Main Index | Thread Index
- Prev by Date: Re: java question
- Next by Date: libpcap for iplogger
- Prev by thread: Re: java question
- Next by thread: java question
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links