java - Check for Broken Pipe only when IOException is thrown -
when writing outputstream
throw ioexception
exception if remote machine down, or has disconnected. now, want call specific method when (and only) pipe broken. problem ioexception
not have code
or errno
property check error. , way able achieve by
try { stream.write(message.getbytes("utf8")); stream.flush(); } catch (ioexception e) { if (e.getmessage().equals("sendto failed: epipe (broken pipe)")) { // perform specific action } else { e.printstacktrace(); } }
obviously not perfect way achieve such thing. suggestion efficient solution?
in java, there no
brokenpipeexception
specifically. type of error found wrapped in different exception, suchsocketexception
orioexception
.
so can achieve same using string#contains()
method
if(e.getmessage().contains("broken pipe")){ // whatever want }
Comments
Post a Comment