• 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

Exception Problems

 
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everybody,
I am in the process of making some programs and decided to throw some customised error and forced to catch my errors as they have been thrown in my various classes as given belown. e.g. testException
But surprised to find that when I tried CheckInteger program I need not to catch any exception and it automatically handles the error, though its Constructor of integer class throws NumberFormatException.
How can I achieve same thing as in my testExceptionprogram as has been achieved in CheckInteger where its constructor throws an error but I need not to explicitly catch the same.
regards,
Arun





[ December 04, 2002: Message edited by: Cindy Glass ]
 
arun mahajan
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps this question sounds stupid but I'd appreciate if someone answer this. Pl help...
regards,
Arun
 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The key is that NumberFormatException is descended from RuntimeException. From the API specification - " A method is not required to declare in its throws clause any subclasses of RuntimeException that might be thrown during the execution of the method but not caught."
So, to accomplish the behavior, extend RuntimeException.
HOWEVER, consider this carefully. RuntimeExceptions are generally used to handle (essentially) programming errors. It looks like your SmartMessageException might fit the bill, if that's the only way that that exception might be used (if the value passed in isn't one of the enumerated constants). But otherwise, if someone might create that SmartMessageException and really want it to be caught and dealt with, don't subclass RuntimeException.
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you use

public void startServer() throws Exception

then you won't have to catch it. Is that what you were asking?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic