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: "Thomas O'Dowd" <tom@example.com>
- Date: Thu, 14 Jun 2001 00:47:11 +0900
- Content-Disposition: inline
- Content-Type: text/plain; charset=us-ascii
- In-Reply-To: <3B278493.388731B4@example.com>; from 9915104t@example.com on Thu, Jun 14, 2001 at 12:19:47AM +0900
- References: <3B278493.388731B4@example.com>
- Reply-To: tlug@example.com
- Resent-From: tlug@example.com
- Resent-Message-ID: <mPGABD.A._iG.1n4J7@example.com>
- Resent-Sender: tlug-request@example.com
- User-Agent: Mutt/1.2.5i
use a loop with an exit condition, or an infinite loop with a break, or ... int someInt; while() { try { someInt = Integer.parseInt(readUserInput()); if(someInt >= 1 && someInt <= 10) break; } catch (NumberFormatException) { ; } } Try not to create and throw new exceptions also when they are not needed. Tom. On Thu, Jun 14, 2001 at 12:19:47AM +0900, 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? > > -- > B0Ti. > > > > ----------------------------------------------------------------------- > Next Nomikai Meeting: Fri, June 15 19:30- Tengu Tokyo Eki-Mae > Next Technical Meeting: Sat, July 14 13:30- > ----------------------------------------------------------------------- > more info: http://www.tlug.gr.jp Sponsor: Global Online Japan > -- Thomas O'Dowd. - Nooping - http://nooper.com tom@example.com - Testing - http://nooper.co.jp/labs
- Follow-Ups:
- Re: java question
- From: B0Ti <9915104t@example.com>
- References:
- java question
- From: B0Ti <9915104t@example.com>
Home | Main Index | Thread Index
- Prev by Date: java question
- Next by Date: Re: drive backup (was: Unicode TTF containing CJK?)
- Prev by thread: java question
- Next by thread: Re: java question
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links