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 ]
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.