Re: how to write a class that need catch?
Sunday, February 20, 2005 06:51 AM
Either you add your "throws" for a checked exception, or you just fail to catch one that is thrown by a method you call.
Is this what you mean? but this is so basic, are you asking something else? because even in the example you gave, the caller can catch a more general parent type, on up to Throwable even, rather than the specific type of checked exception you throw.
And if you throw a subclass of RuntimeException rather than of Exception, the caller does not have to catch it, because that's "unchecked". but there is a movement nowadays to prefer using unchecked rather than checked exceptions.