Mailing List Archive

Support open source code!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: java question



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


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links