ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  Best Practices for Exception Handling
Subject:   declaring impossible exceptions
Date:   2003-11-21 09:19:42
From:   anonymous2
I think it's important that Java allows this:


public void someMethod() throws Exception{
}


OK, so no method should "throws Exception", but if that were "throws UserNotFoundException", I think that would be just fine.


Keep in mind that the throws clause is part of the method signature, and thus part of the API. You might want to do this if you think that a future version of your library might throw the exception and want your clients to have an easy transition. Or if you think subclasses that override the method will need to throw that exception, you have to declare it in the base class--even if the base class implementation never actually throws it.


1 to 1 of 1
  1. declaring impossible exceptions
    2003-11-21 16:58:56  anonymous2 [View]

1 to 1 of 1