| Author |
need help with exception
|
boki markos
Greenhorn
Joined: May 10, 2009
Posts: 5
|
|
basically i need to ask the user if they wanna change dimensions of silo 1 and then silo 2.. but i want to put in an exception to catch any numbers, or other characters that arent letters... which exception would i use?
[edit]Add some new lines so as to fit all code into width of screen. CR.[/edit]
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
I presume you have already initialised num to -1? In which case NumberFormatException looks correct.
But those multiple if-elses don't. Imagine how complicated that would look if you had a silo3 or a silo4. Is there any way of passing a reference to the silo to change, so you can call
s.setHeight(num);
or
s.setRadius(num);
I am not happy to see a System.exit() call. That is probably safe in this instance, but if you have a larger application, you might interfere with other processes going on, and have something disastrous like a file half-written and not properly closed.
There are other dialogs available in JOptionPane; there is one which can return YES/NO, which would probably fit your purposes better than input dialog for getting YES/NO.
|
 |
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8567
|
|
|
You might also want to consider a numeric text field or a JSpinner
|
[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
|
 |
 |
|
|
subject: need help with exception
|
|
|