Reputation: 551
I have one method that transfers data from one socket to another. Now whenever there is some problem either on any socket I need to detect which socket has caused Socket Exception. Is this possible to detect it from Socket Exception object ?
Upvotes: 0
Views: 86
Reputation: 48692
Not from the exception itself, but you can from the context. If the code manipulates only one socket, clearly the exception must relate to that socket.
It sounds like you are not handling your exceptions at an appropriate level, instead handling (catching) a low level exception at a high level part of your program, and expecting to be able to do low level handling at that point.
Consider catching the exception at an intermediate level, partially handling it, then rethrowing it. You might want to do exception translation (chaining) at that point.
Upvotes: 2
Reputation: 2119
Simple answer is 'NO'. Since Exceptions in Java are made to notify an unexpected behavior, they are not made to store any reference to the object in error. You can see in this exception class or any of it's supertypes. None of them is able to hold reference to any object.
Upvotes: -1
Reputation: 69470
You can't get it from the excpetion, because ther is no property where the socket is saved.
Upvotes: 1