List of usage examples for java.lang Throwable getStackTrace
public StackTraceElement[] getStackTrace()
From source file:com.jk.framework.util.FakeRunnable.java
/** * Prints the stack trace./*from w w w . ja v a 2s . c o m*/ */ public static void printStackTrace() { final Throwable t = new Throwable(); final StackTraceElement trace[] = t.getStackTrace(); for (final StackTraceElement element : trace) { System.err.println(element.getClassName() + "." + element.getMethodName()); } }
From source file:org.alfresco.repo.node.cleanup.NodeCleanupRegistry.java
/** * Calls all registered cleaners in order, without transactions or authentication. * The return messages are aggregated.//from w ww. j a v a 2 s. co m */ public List<String> doClean() { List<String> results = new ArrayList<String>(100); for (NodeCleanupWorker cleanupWorker : cleanupWorkers) { try { results.addAll(cleanupWorker.doClean()); } catch (Throwable e) { // This failed. The cleaner should be handling this, but we can't guarantee it. logger.error("NodeCleanupWork doesn't handle all exception conditions: " + cleanupWorker.getClass().getName()); StringBuilder sb = new StringBuilder(1024); StackTraceUtil.buildStackTrace("Node cleanup failed: " + " Worker: " + cleanupWorker.getClass().getName() + "\n" + " Error: " + e.getMessage(), e.getStackTrace(), sb, 0); results.add(sb.toString()); } } return results; }
From source file:org.apache.pig.backend.hadoop.executionengine.mapreduceExec.PigMapReduce.java
/** * Nothing happens here./*from w ww . j av a 2 s.c o m*/ */ public void close() throws IOException { try { if (evalPipe != null) evalPipe.finishPipe(); } catch (Throwable t) { log.error(t); // Convert to IOException to ensure Hadoop handles it correctly ... IOException ioe = new IOException(t.getMessage()); ioe.setStackTrace(t.getStackTrace()); throw ioe; } }
From source file:org.esa.cci.sst.tools.BasicTool.java
public final ErrorHandler getErrorHandler() { if (errorHandler == null) { synchronized (this) { if (errorHandler == null) { errorHandler = new ErrorHandler() { @Override//from w w w. ja v a 2 s . c o m public void terminate(ToolException e) { final Logger localLogger = SstLogging.getLogger(); localLogger.log(Level.SEVERE, e.getMessage(), e); if (e.getCause() != null) { if (localLogger.isLoggable(Level.FINEST)) { for (final StackTraceElement element : e.getCause().getStackTrace()) { localLogger.log(Level.FINEST, element.toString()); } } e.getCause().printStackTrace(System.err); } System.exit(e.getExitCode()); } @Override public void warn(Throwable t, String message) { final Logger localLogger = SstLogging.getLogger(); localLogger.log(Level.WARNING, message, t); if (localLogger.isLoggable(Level.FINEST)) { for (final StackTraceElement element : t.getStackTrace()) { localLogger.log(Level.FINEST, element.toString()); } } } }; } } } return errorHandler; }
From source file:com.chaosinmotion.securechat.server.json.ReturnResult.java
/** * Generate an error result. This is used to aid in debugging on the * client side. This also initializes an array to help diagnose the * problem client-side.// www. j a va2 s . c o m * * Normally this should never be called. * * @param exception */ public ReturnResult(Throwable th) { success = false; errorCode = Errors.ERROR_EXCEPTION; errorMessage = "Internal exception: " + th.getMessage(); exception = new ArrayList<String>(); boolean cflag = false; do { if (cflag) { exception.add("Caused by " + th.getMessage()); } else { cflag = true; } StackTraceElement[] e = th.getStackTrace(); int maxlen = e.length; th = th.getCause(); if (th != null) { // If there is a cause, we trim the items we show for this // exception by removing the tail of the stack trace that // is in common. This helps with reading the stack frame. StackTraceElement[] n = th.getStackTrace(); int nlen = n.length; while ((maxlen > 0) && (nlen > 0)) { StackTraceElement el = e[maxlen - 1]; StackTraceElement nl = n[nlen - 1]; if (el.equals(nl)) { --maxlen; --nlen; } else { break; } } // Make sure we show at least one item, unless we don't have // a stack frame (which can happen sometimes) if (maxlen == 0) { maxlen++; if (maxlen > e.length) maxlen = e.length; } } // Now add the stack frame for (int i = 0; i < maxlen; ++i) { exception.add(" " + e[i].toString()); } } while (th != null); }
From source file:org.apache.pig.backend.hadoop.executionengine.mapreduceExec.PigMapReduce.java
public void reduce(Tuple key, Iterator<IndexedTuple> values, OutputCollector<WritableComparable, Writable> output, Reporter reporter) throws IOException { PigMapReduce.reporter = reporter;//from w w w . j a va 2 s . com try { oc = output; if (evalPipe == null) { setupReducePipe(properties); } DataBag[] bags = new DataBag[inputCount]; Datum groupName = key.getField(0); Tuple t = new Tuple(1 + inputCount); t.setField(0, groupName); for (int i = 1; i < 1 + inputCount; i++) { bags[i - 1] = BagFactory.getInstance().newDefaultBag(); t.setField(i, bags[i - 1]); } while (values.hasNext()) { IndexedTuple it = values.next(); t.getBagField(it.index + 1).add(it.toTuple()); } for (int i = 0; i < inputCount; i++) { if (isInner[i] && t.getBagField(1 + i).size() == 0) return; } evalPipe.add(t); } catch (Throwable tr) { log.error(tr); // Convert to IOException to ensure Hadoop handles it correctly ... IOException ioe = new IOException(tr.getMessage()); ioe.setStackTrace(tr.getStackTrace()); throw ioe; } }
From source file:org.ow2.proactive_grid_cloud_portal.scheduler.client.SchedulerRestClient.java
private static Exception rebuildServerSideException(ExceptionToJson json) throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { Throwable serverException = json.getException(); String exceptionClassName = json.getExceptionClass(); String errMsg = json.getErrorMessage(); if (errMsg == null) { errMsg = "An error has occurred."; }//from w ww .j a v a2 s . c o m if (serverException != null && exceptionClassName != null) { Class<?> exceptionClass = toClass(exceptionClassName); if (exceptionClass != null) { // wrap the exception serialized in JSON inside an // instance of // the server exception class Constructor<?> constructor = getConstructor(exceptionClass, Throwable.class); if (constructor != null) { return (Exception) constructor.newInstance(serverException); } constructor = getConstructor(exceptionClass, String.class); if (constructor != null) { Exception built = (Exception) constructor.newInstance(errMsg); built.setStackTrace(serverException.getStackTrace()); return built; } } } Exception built = new Exception(errMsg); if (serverException != null) { built.setStackTrace(serverException.getStackTrace()); } return built; }
From source file:org.sherlok.PipelineLoader.java
/** Just loads that pipeline. No caching. */ UimaPipeline load(PipelineDef pipelineDef) throws SherlokException { pipelineDef.validate("could not validate pipeline wit Id '" + pipelineDef.getId() + "',"); // just to make sure... // 3. create a list of engines (and their bundles) to resolve List<EngineDef> engineDefsUsedInP = list(); Set<BundleDef> bundleDefsToResolve = set(); for (String pengineId : pipelineDef.getEnginesFromScript()) { EngineDef en = controller.getEngineDef(pengineId); if (en == null) { throw new SherlokException(); }/* www . j av a 2 s. c o m*/ validateNotNull(en, "could not find engine '" + pengineId + "' as defined in pipeline '" + pipelineDef.getId() + "'"); BundleDef b = en.getBundle(); validateNotNull(b, "could not find bundle '" + b + "' that is required by engine '" + en + "'"); LOG.trace("adding engineDef '{}' with bundleDef '{}'", en, b); engineDefsUsedInP.add(en); bundleDefsToResolve.add(b); } // 4. solve (download) bundle dependencies try { solveDependencies(pipelineDef.getName(), pipelineDef.getVersion(), bundleDefsToResolve, engineDefsUsedInP.size()); } catch (ArtifactResolutionException e) { throw new SherlokException("Failed to resolve solve pipeline dependencies") .setObject(pipelineDef.getId()).setDetails(e.getMessage()); } catch (DependencyCollectionException e) { throw new SherlokException("Failed to collect pipeline dependencies").setObject(pipelineDef.getId()) .setDetails(e.getMessage()); } catch (Exception e) { throw new RuntimeException(e); // should not happen } // 5. create UimaPipeline UimaPipeline uimaPipeline; try { uimaPipeline = new UimaPipeline(pipelineDef, engineDefsUsedInP); } catch (IOException | UIMAException e) {// other SherlokErrors catched LOG.warn("could not initialize UIMA pipeline", e); Throwable rootCause = ExceptionUtils.getRootCause(e); if (rootCause instanceof RutaParseRuntimeException) { throw new SherlokException(rootCause.getMessage()).setObject(pipelineDef.toString()) .setDetails(rootCause.getStackTrace()); } else { throw new SherlokException("could not initialize UIMA pipeline").setObject(pipelineDef.toString()) .setDetails(e.getStackTrace()); } } return uimaPipeline; }
From source file:own.projects.lemiroapp.GameModeActivity.java
private void setDefaultUncaughtExceptionHandler() { try {//from w w w.j a v a2 s.c om Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { StackTraceElement[] trace = e.getStackTrace(); String tracem = ""; for (int i = 0; i < trace.length; i++) { tracem += trace[i] + "\n"; } Log.e("GameModeActivity", "Uncaught Exception detected in thread {}" + t + e + "\n" + tracem); final String message = e.getMessage(); //display message so that the user sees that something went wrong runOnUiThread(new Runnable() { @Override public void run() { new AlertDialog.Builder(THIS).setIcon(android.R.drawable.ic_dialog_info) .setTitle("Error").setMessage(message).setCancelable(false) .setNeutralButton("Quit", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { finish(); } }).show(); } }); } }); } catch (SecurityException e) { Log.e("GameModeActivity", "Could not set the Default Uncaught Exception Handler" + e); } }
From source file:net.ymate.framework.webmvc.AbstractWebErrorProcessor.java
private StringBuilder __doExceptionToString(Throwable e) { StringBuilder _errSB = new StringBuilder(); if (e != null) { _errSB.append("-- Exception: ").append(e.getClass().getName()).append("\n"); _errSB.append("-- Message: ").append(e.getMessage()).append("\n"); ////ww w . java 2 s . com _errSB.append("-- StackTrace:\n"); StackTraceElement[] _stacks = e.getStackTrace(); for (StackTraceElement _stack : _stacks) { _errSB.append("\t at ").append(_stack).append("\n"); } } return _errSB; }