Refined exception handling for socket error