try { // code here } catch (IOException) { Disconnected(); } catch (Exception ex) { Disconnected(); log.Error(ex); } Code: C#