> necessarily mean that the data was successfully sent.
> Therefore I strongly recommend to insert something like this:
> if (output.checkError())
> throw new IOException("something bad happened");
>On Feb 7, 7:17 pm, Thomas Fritsch <i.dont.like.s...@invalid.com>
>wrote:
>> necessarily mean that the data was successfully sent.
>> Therefore I strongly recommend to insert something like this:
>> if (output.checkError())
>> throw new IOException("something bad happened");
I wouldn't even throw IOException
because there could be NUMEROUS conditions,
such as unable to open files, can not connect,
lost connection, stream lost, file does not exist,
file has wrong access permisions, etc.
All of these are COMPLETELY different conditions
and need to be handled in the most appropriate place
with fine enough granularity for the entire app to
be able to handle and recover from ANY condition
imaginable.
Instead, you create ConnectionLostException, extending
SocketException, where you handle several types of
those kinds of errors.
Or, InalidParameter exception, or FileNotFoundException,
or ServerDeniedAccessException, or AuthorizationRequiredException
and things like that.
In this case, you should be able to handle just about
any error condition imaginable and recover from it
in the most graceful manner instead of restarting the
whole thing from top or requiring user to reboot.
:--}
>The above helped solve the problem. The timer was causing some issues
>with the socket and we were able to determine the same using
>output.checkError();
Just use TimeOutException and try to retry to reconnect
and redo it on the LOWEST level possible instead of letting
the higher levels handle that exception, in which case,
they'd have to retry the whole operation from the top.
I am handling this exact error condition just perfectly
to the point where you can unplug the network cable
and it stays on the lowest possible level retrying it.
Works like a champ. You can not possibly do it better.
Not possible, even in principle.
>Thanks for your support!
>
>Regards,
>Rajat
Esmond Pitt - 09 Feb 2007 00:09 GMT
> I wouldn't even throw IOException
The problem is that PrintWriter won't tell you what the actual exception
was, except that by definition of the methods implemented it must have
been an IOException or a subclass.
Really you shouldn't use PrintWriter or PrintStream over the network at
all, you're just asking for untraceable trouble.