A little more context: I have a listener class that listens on network connections. Its listen method should not be called on it twice. What should I throw when it is?
A little more context: I have a listener class that listens on network connections.
Share
If you want to use a predefined exception, you might throw
IllegalStateException, since the object is already in thelisteningstate.If you do this, though, there should be a way for the client to find out if
listenhas already been called. E.g. anisListening()method.You might also create your own exception, possibly extended from IOException, since this is an IO Problem. Presumably, attempting to listen more than once fails since the network resource has already been used on the first listen. (Similar to sockets binding.)