try { .... } catch (Exception ex) { if (ex != null) { try { ex.printStackTrace(); } catch(Exception ex1) { .... } } }