According to the specification for send(), you are catching everything that it can throw.
Remember that a catch() clause will match an exception of the specified type, or an exception of any subclass of the specified type. So there is no point catching IOException, then later trying to catch InterruptedIOException, as InterruptedIOException is a subclass of IOException. For example:
Code:
try {
throw new InterruptedIOException ();
}
catch (IOException e) {
// the exception will get caught here, because
// InterruptedIOException is a subclass of IOException
}
catch (InterruptedIOException e) {
// this is unreachable
}
Because the code in the second catch() clause is unreachable, I doubt that this would even compile... you've got around that by sorting exceptions out in a different way. But the result is similar.
Code:
try {
throw new InterruptedIOException ();
}
catch (Exception e) {
// any subclass of Exception will get caught here
if (e instanceof {
// an InterruptedIOException is an instance of
// IOException, so this code gets executed
}
if (e instanceof InterruptedIOException) {
// because there is no "else", this gets executed too!
// if it was written "else if" then this would be
// unreachable
}
}
You can make sure that you catch everything that can possibly be caught, by catching everything that can be thrown:
Code:
try {
// do stuff here
}
catch (Throwable t) {
// if anything is thrown, you will catch it here
}
Of course, if a failed send() doesn't throw anything, there'll be nothing to catch. Message objects have a timestamp property, indicating when they were sent... what value does this have if the Message isn't sent? (The specification doesn't say, so it may not be reliable).
Graham.