Example #1
0
 /**
  * Returns an string array representation of the specified throwable.
  *
  * @param th throwable
  * @return string array
  */
 private static String[] toArray(final Throwable th) {
   final StackTraceElement[] st = th.getStackTrace();
   final String[] obj = new String[st.length + 1];
   obj[0] = th.toString();
   for (int i = 0; i < st.length; i++) obj[i + 1] = "  " + st[i];
   return obj;
 }
Example #2
0
 /**
  * Returns a more user-friendly error message for the specified exception.
  *
  * @param ex throwable reference
  * @return error message
  */
 public static String message(final Throwable ex) {
   debug(ex);
   if (ex instanceof BindException) return SRV_RUNNING;
   if (ex instanceof LoginException) return ACCESS_DENIED;
   if (ex instanceof ConnectException) return CONNECTION_ERROR;
   if (ex instanceof SocketTimeoutException) return TIMEOUT_EXCEEDED;
   if (ex instanceof SocketException) return CONNECTION_ERROR;
   String msg = ex.getMessage();
   if (msg == null || msg.isEmpty()) msg = ex.toString();
   if (ex instanceof FileNotFoundException) return info(RES_NOT_FOUND_X, msg);
   if (ex instanceof UnknownHostException) return info(UNKNOWN_HOST_X, msg);
   return msg;
 }