List of usage examples for java.lang Throwable getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.github.michalbednarski.intentslab.Utils.java
public static String describeException(Throwable exception) { String exceptionName = exception.getClass().getName(); exceptionName = afterLastDot(exceptionName); return exceptionName + ": " + exception.getMessage(); }
From source file:com.heliosdecompiler.helios.bootloader.Bootloader.java
private static void displayError(Throwable t) { t.printStackTrace();/*from ww w .j a v a 2s .co m*/ StringWriter writer = new StringWriter(); t.printStackTrace(new PrintWriter(writer)); JOptionPane.showMessageDialog(null, writer.toString(), t.getClass().getSimpleName(), JOptionPane.INFORMATION_MESSAGE); }
From source file:com.onesignal.OneSignalRestClient.java
private static void makeRequest(String url, String method, JSONObject jsonBody, ResponseHandler responseHandler) { HttpURLConnection con = null; int httpResponse = -1; String json = null;/*w ww. j av a 2 s . co m*/ try { con = (HttpURLConnection) new URL(BASE_URL + url).openConnection(); con.setUseCaches(false); con.setDoOutput(true); con.setConnectTimeout(TIMEOUT); con.setReadTimeout(TIMEOUT); if (jsonBody != null) con.setDoInput(true); con.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); con.setRequestMethod(method); if (jsonBody != null) { String strJsonBody = jsonBody.toString(); OneSignal.Log(OneSignal.LOG_LEVEL.DEBUG, method + " SEND JSON: " + strJsonBody); byte[] sendBytes = strJsonBody.getBytes("UTF-8"); con.setFixedLengthStreamingMode(sendBytes.length); OutputStream outputStream = con.getOutputStream(); outputStream.write(sendBytes); } httpResponse = con.getResponseCode(); InputStream inputStream; Scanner scanner; if (httpResponse == HttpURLConnection.HTTP_OK) { inputStream = con.getInputStream(); scanner = new Scanner(inputStream, "UTF-8"); json = scanner.useDelimiter("\\A").hasNext() ? scanner.next() : ""; scanner.close(); OneSignal.Log(OneSignal.LOG_LEVEL.DEBUG, method + " RECEIVED JSON: " + json); if (responseHandler != null) responseHandler.onSuccess(json); } else { inputStream = con.getErrorStream(); if (inputStream == null) inputStream = con.getInputStream(); if (inputStream != null) { scanner = new Scanner(inputStream, "UTF-8"); json = scanner.useDelimiter("\\A").hasNext() ? scanner.next() : ""; scanner.close(); OneSignal.Log(OneSignal.LOG_LEVEL.WARN, method + " RECEIVED JSON: " + json); } else OneSignal.Log(OneSignal.LOG_LEVEL.WARN, method + " HTTP Code: " + httpResponse + " No response body!"); if (responseHandler != null) responseHandler.onFailure(httpResponse, json, null); } } catch (Throwable t) { if (t instanceof java.net.ConnectException || t instanceof java.net.UnknownHostException) OneSignal.Log(OneSignal.LOG_LEVEL.INFO, "Could not send last request, device is offline. Throwable: " + t.getClass().getName()); else OneSignal.Log(OneSignal.LOG_LEVEL.WARN, method + " Error thrown from network stack. ", t); if (responseHandler != null) responseHandler.onFailure(httpResponse, null, t); } finally { if (con != null) con.disconnect(); } }
From source file:com.icesoft.faces.util.CoreUtils.java
public static boolean throwablesEqual(Throwable th1, Throwable th2) { if (th1 == null && th2 == null) return true; if (th1 == null || th2 == null) return false; if (th1.getClass() != th2.getClass()) return false; if (!th1.getMessage().equals(th2.getMessage())) return false; StackTraceElement[] st1 = th1.getStackTrace(); StackTraceElement[] st2 = th2.getStackTrace(); if (st1.length != st2.length) return false; for (int i = 0; i < st1.length; i++) { if (!st1[i].equals(st2[i])) return false; }/*w w w . j a va2s . c o m*/ return true; }
From source file:cc.sion.core.utils.Exceptions.java
/** * ??????, ?//from ww w. j ava 2s . c o m */ public static String getErrorMessageWithNestedException(Throwable ex) { Throwable nestedException = ex.getCause(); return new StringBuilder().append(ex.getMessage()).append(" nested exception is ") .append(nestedException.getClass().getName()).append(":").append(nestedException.getMessage()) .toString(); }
From source file:net.algart.simagis.live.json.minimal.SimagisLiveUtils.java
private static JSONObject toJSONError(Throwable x, JSONObject log) { final StringWriter stackTrace = new StringWriter(); x.printStackTrace(new PrintWriter(stackTrace)); final JSONObject error = new JSONObject(); try {/*from www .ja v a 2 s . c o m*/ error.put("error", x.getClass().getSimpleName()); error.put("exception", x.getClass().getName()); error.put("message", x.getLocalizedMessage()); error.put("stackTrace", stackTrace.toString()); if (log != null) { error.put("log", log); } } catch (JSONException e) { throw new AssertionError(e); } return error; }
From source file:com.tussle.main.Utility.java
public static JsonValue exceptionToJson(Throwable ex) { JsonValue topValue = new JsonValue(JsonValue.ValueType.object); JsonValue exceptionClass = new JsonValue(ex.getClass().toString()); topValue.addChild("Exception Class", exceptionClass); if (ex.getLocalizedMessage() != null) { JsonValue exceptionMessage = new JsonValue(ex.getLocalizedMessage()); topValue.addChild("Exception Message", exceptionMessage); }//from ww w . jav a 2 s .c o m if (ex.getCause() != null) { JsonValue exceptionCause = new JsonValue(ex.getCause().toString()); topValue.addChild("Exception Cause", exceptionCause); } JsonValue stackTrace = new JsonValue(JsonValue.ValueType.array); for (StackTraceElement element : ex.getStackTrace()) stackTrace.addChild(new JsonValue(element.toString())); topValue.addChild("Stack Trace", stackTrace); return topValue; }
From source file:com.espertech.esper.core.ResultDeliveryStrategyImpl.java
/** * Handle the exception, displaying a nice message and converting to {@link EPException}. * @param logger is the logger to use for error logging * @param t is the throwable/* ww w . j av a 2 s.c o m*/ * @param params the method parameters * @param subscriber the object to deliver to * @param method the method to call * @throws EPException converted from the passed invocation exception */ protected static void handleThrowable(Log logger, Throwable t, Object[] params, Object subscriber, FastMethod method) { String message = "Unexpected exception when invoking method '" + method.getName() + "' on subscriber class '" + subscriber.getClass().getSimpleName() + "' for parameters " + ((params == null) ? "null" : Arrays.toString(params)) + " : " + t.getClass().getSimpleName() + " : " + t.getMessage(); logger.error(message, t); }
From source file:io.stallion.monitoring.ExceptionInfo.java
public static ExceptionInfo newForException(Throwable e) { ExceptionInfo info = new ExceptionInfo(); info.thrownAt = utcNow();//w w w .j av a 2 s. c om info.stackTraces = ExceptionUtils.getRootCauseStackTrace(e); if (e instanceof InvocationTargetException) { e = ((InvocationTargetException) e).getTargetException(); } info.className = e.getClass().getSimpleName(); info.message = e.getMessage(); info.requestUrl = request().getRequestUrl(); info.requestUrlWithQuery = request().getRequestUrlWithQuery(); info.requestMethod = request().getMethod(); info.remoteAddr = request().getRemoteAddr(); info.actualIp = request().getActualIp(); info.requestHeaders = map(); for (String name : Collections.list(request().getHeaderNames())) { info.requestHeaders.put(name, request().getHeader(name)); } try { info.setRequestBody(request().getContent()); } catch (RuntimeException e2) { Log.info("Error logging the exception - could not get the request body: {0}", e2); } if (!Context.getUser().isAnon()) { info.setEmail(Context.getUser().getEmail()); info.setUsername(Context.getUser().getUsername()); info.setUserId(Context.getUser().getId()); info.setValetId(Context.getValetUserId()); } return info; }
From source file:com.amazonaws.util.Throwables.java
/** * Returns the root cause of the given throwable, or null if the given * throwable is null. If the root cause is over 1000 level deep, the * original throwable will be returned defensively as this is heuristically * considered a circular reference, however unlikely. */// www. ja v a2s . co m public static Throwable getRootCause(Throwable orig) { if (orig == null) return orig; Throwable t = orig; // defend against (malicious?) circularity for (int i = 0; i < 1000; i++) { Throwable cause = t.getCause(); if (cause == null) return t; t = cause; } // Too bad. Return the original exception. LogFactory.getLog(Throwables.class) .debug("Possible circular reference detected on " + orig.getClass() + ": [" + orig + "]"); return orig; }