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?

as mentioned here

in java, there no brokenpipeexception specifically. type of error found wrapped in different exception, such socketexception or ioexception.

so can achieve same using string#contains() method

if(e.getmessage().contains("broken pipe")){ // whatever want  } 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -