aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes need help with exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "need help with exception" Watch "need help with exception" New topic
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: 40064
    
  28
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: 10535
    
    9

You might also want to consider a numeric text field or a JSpinner


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need help with exception