Is there a way to get some details regarding exception safety aspects of Java's standard classes? Mainly working with C++ and C#, I'm confused with Java exception specifications, so I need to understand the proper way of working with exceptions.
To be more specific, let's consider ServerSocket
. It starts listening for incoming connections as soon as its object is constructed. Then, you should use accept()
to accept the connection (if someone tries to connect).
In case you've previously configured your server socket with setSoTimeout()
, there's a change that accept()
will throw SocketTimeoutException
because nobody tried to connect in a specified period of time. That's fine, server socket is still usable, so you just call accept()
once again.
But SocketTimeoutException
is not the only thing that accept()
may throw. What does all the other exceptions mean? If I wrap call to accept()
with 2 catch clauses: for SocketTimeoutException
and IOException
, can I still safely use the related ServerSocket
instance after I got into IOException
clause?
I'd really appreciate both Java-wide and ServerSocket-specific answers.