• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

need help with exception

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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]
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might also want to consider a numeric text field or a JSpinner
reply
    Bookmark Topic Watch Topic
  • New Topic