I believe that checking for dynamic exceptions is just another name for runtime exceptions.
Although I believe in static exception checking, the Java static exception checking method does have problems with interface implementations.
Say we have an IParser . What relevant exceptions can its parse() method raise? Maybe a SyntaxErrorException . Now we want ServerResponseParserFromURL be used this way:
class ServerResponseParserFromURL implements IParser { .... }; .... try { IParser parser = new ServerResponseParser(new URL("http://example.com/test.htm")); parser.parse(); .... }
Here's the problem - an IParser implementation may fire, say, a NoRouteToHostException . Thus, we cannot use a beautiful and concise form and need to return to a long form:
class ServerResponseParser implements IParser { .... }; .... try { String response = getServerResponse(new URL("http://example.com/test.htm")); IParser parser = new ServerResponseParser(response); parser.parse(); .... }
As you can see, in practice, our IParser is an IStringParser , not a common IParser .
Although this may be acceptable in this particular case, it complicates the situation when we want to provide IParser as one of the arguments to f . Say, in order to be able to analyze the response of the server identified by the url, we cannot just pass the ServerResponseParser object and url - we need to find a way to pass the getServerResponse method f .
source share