List of usage examples for java.lang Exception setStackTrace
public void setStackTrace(StackTraceElement[] stackTrace)
From source file:com.jkoolcloud.tnt4j.utils.Utils.java
/** * Print given message, stack trace to the underlying print writer * * @param msg//from w ww . j a v a2 s. co m * user defined message * @param trace * stack trace * @param out * print writer where output is written */ public static void printStackTrace(String msg, StackTraceElement[] trace, PrintWriter out) { Exception ex = new Exception(msg); ex.setStackTrace(trace); ex.printStackTrace(out); }
From source file:org.paxle.tools.sysmon.impl.DiskspaceMonitoring.java
public StatusVariable getStatusVariable(String name) throws IllegalArgumentException { if (!VAR_NAMES.contains(name)) { throw new IllegalArgumentException("Invalid Status Variable name " + name); }//from ww w .j a v a 2 s.c o m if (name.equalsIgnoreCase(VAR_SPACE_FREE)) { long freeDisk = -1; try { /* * Query free disk space. * * We need to call this within a separate thread due to the following bug: * https://bugs.pxl.li/view.php?id=278 */ FreeSpaceThread queryThread = new FreeSpaceThread(); queryThread.start(); // waiting for the result queryThread.join(10000); if (queryThread.isAlive()) { final StackTraceElement[] stackTrace = queryThread.getStackTrace(); final Exception rte = new RuntimeException("Query thread is still alive"); rte.setStackTrace(stackTrace); this.logger.warn("FreeSpace query thread is still alive!", rte); } else { freeDisk = queryThread.freeSpace; } } catch (InterruptedException e) { // ignore this } return new StatusVariable(name, StatusVariable.CM_GAUGE, freeDisk); } else if (name.equalsIgnoreCase(VAR_QUERY_MODE)) { return new StatusVariable(name, StatusVariable.CM_SI, this.queryMode.toString()); } return null; }
From source file:nl.strohalm.cyclos.services.access.AbstractPermissionCheck.java
@Override protected void finalize() throws Throwable { if (!permissionChecked) { if (stackTrace == null) { LOG.warn(/* w ww.j av a 2 s . com*/ "PermissionCheck object created without actually checking permission. Did you forget a call to check() or hasPermission()? Set the -Dcyclos.tracePermissionChecks=true system argument to view where this permission object was created"); } else { Exception ex = new Exception(); ex.setStackTrace(stackTrace); LOG.warn( "PermissionCheck object created without actually checking permission. Did you forget a call to check() or hasPermission()?", ex); } } }
From source file:ca.ualberta.cs.c301_crowdclient.CrowdClient.java
private CrowdSourcerEntry updateEntry() throws Exception { HttpResponse response = httpclient.execute(httpPost); String status = response.getStatusLine().toString(); System.out.println(status);/* w ww . j a v a 2 s . co m*/ HttpEntity entity = response.getEntity(); CrowdSourcerEntry updatedEntry = null; if (entity != null) { InputStream is = entity.getContent(); String jsonStringVersion = convertStreamToString(is); Type entryType = CrowdSourcerEntry.class; try { updatedEntry = gson.fromJson(jsonStringVersion, entryType); } catch (Exception e) { Exception myException = new Exception("There was an error " + "getting the entry from JSON. Here is the " + "httpPost entity content: " + convertStreamToString(httpPost.getEntity().getContent()) + "\n" + "CrowdSource response:\n" + jsonStringVersion); myException.setStackTrace(e.getStackTrace()); throw myException; } } entity.consumeContent(); return updatedEntry; }
From source file:org.mule.module.json.transformers.ObjectToJson.java
/** * The reason of having this is because the original exception object is way too * complex and it breaks JSON-lib./*w ww. j av a2s. c o m*/ */ private Exception getException(Throwable t) { Exception returnValue = null; List<Throwable> causeStack = new ArrayList<Throwable>(); for (Throwable tempCause = t; tempCause != null; tempCause = tempCause.getCause()) { causeStack.add(tempCause); } for (int i = causeStack.size() - 1; i >= 0; i--) { Throwable tempCause = causeStack.get(i); // There is no cause at the very root if (i == causeStack.size()) { returnValue = new Exception(tempCause.getMessage()); returnValue.setStackTrace(tempCause.getStackTrace()); } else { returnValue = new Exception(tempCause.getMessage(), returnValue); returnValue.setStackTrace(tempCause.getStackTrace()); } } return returnValue; }
From source file:org.apache.juneau.rest.client.RestClient.java
/** * Perform a generic REST call./*w w w . j a va2s . com*/ * * @param method The method name (e.g. <js>"GET"</js>, <js>"OPTIONS"</js>). * @param url The URL of the remote REST resource. Can be any of the following: {@link String}, {@link URI}, {@link URL}. * @param hasContent Boolean flag indicating if the specified request has content associated with it. * @return A {@link RestCall} object that can be further tailored before executing the request * and getting the response as a parsed object. * @throws RestCallException If any authentication errors occurred. */ public RestCall doCall(String method, Object url, boolean hasContent) throws RestCallException { if (isClosed) { Exception e2 = null; if (closedStack != null) { e2 = new Exception("Creation stack:"); e2.setStackTrace(closedStack); throw new RestCallException( "RestClient.close() has already been called. This client cannot be reused.").initCause(e2); } throw new RestCallException( "RestClient.close() has already been called. This client cannot be reused. Closed location stack trace can be displayed by setting the system property 'org.apache.juneau.rest.client.RestClient.trackCreation' to true."); } HttpRequestBase req = null; RestCall restCall = null; final String methodUC = method.toUpperCase(Locale.ENGLISH); try { if (hasContent) { req = new HttpEntityEnclosingRequestBase() { @Override /* HttpRequest */ public String getMethod() { return methodUC; } }; restCall = new RestCall(this, req, toURI(url)); } else { req = new HttpRequestBase() { @Override /* HttpRequest */ public String getMethod() { return methodUC; } }; restCall = new RestCall(this, req, toURI(url)); } } catch (URISyntaxException e1) { throw new RestCallException(e1); } for (Map.Entry<String, ? extends Object> e : headers.entrySet()) restCall.header(e.getKey(), e.getValue()); if (parser != null && !req.containsHeader("Accept")) req.setHeader("Accept", parser.getPrimaryMediaType().toString()); return restCall; }
From source file:de.dfki.iui.opentok.cordova.plugin.OpenTokPlugin.java
private boolean sendException(String errorMessage) { Exception exc = new OpenTokPluginError(errorMessage); //remove first element form stack trace, since we want the // calling method as first entry in the stack trace // (and not this method itself) StackTraceElement[] stack = exc.getStackTrace(); exc.setStackTrace(getStackTrace(stack, 1, stack.length - 1)); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); exc.printStackTrace(pw);/*from w ww . j a v a 2 s .co m*/ errorMessage = sw.toString(); if (this._exceptionCallback != null) { PluginResult excResult = new PluginResult(PluginResult.Status.ERROR, errorMessage); excResult.setKeepCallback(true); OpenTokPlugin.this._exceptionCallback.sendPluginResult(excResult); return true; } else { LOG.e(PLUGIN_NAME, errorMessage, exc); return false; } }