Menu

#5 Refine interface to throw detailed exception

Unstable (example)
open
nobody
None
5
2014-02-04
2014-02-04
Robert
No

I wanted to use TCPMasterConnection.connect().
The API states, that connect() throws an Exception. I know, that a connect might fail because of e.g. Network problems and I would like to handle those failures.
But I can not handle them properly, because the following code will catch all Exceptions, that do exist, including RuntimeExceptions like NullpointerException... etc:

try {
tcp.connect()
} catch (Exception e) {
// what kind of exception is this?
}

I suggest to change the API for connect to declaire explicitly the thrown exceptions, that the caller should except (e.g. IOException).

Discussion


Log in to post a comment.