Example usage for java.lang Throwable getStackTrace

List of usage examples for java.lang Throwable getStackTrace

Introduction

In this page you can find the example usage for java.lang Throwable getStackTrace.

Prototype

public StackTraceElement[] getStackTrace() 

Source Link

Document

Provides programmatic access to the stack trace information printed by #printStackTrace() .

Usage

From source file:org.apache.pig.backend.hadoop.executionengine.mapreduceExec.PigCombine.java

public void reduce(Tuple key, Iterator<IndexedTuple> values, OutputCollector<Tuple, IndexedTuple> output,
        Reporter reporter) throws IOException {

    try {/*from  w  w  w.j  av  a 2s  .c  o  m*/
        if (evalPipe == null) {
            finalout = new CombineDataOutputCollector(output);
            evalPipe = esp.setupPipe(null, finalout);
            //throw new RuntimeException("combine spec: " + evalSpec + " combine pipe: " + esp.toString());

            bags = new DataBag[inputCount];
            for (int i = 0; i < inputCount; i++) {
                bags[i] = BagFactory.getInstance().newDefaultBag();
            }
        }

        if (PigInputFormat.getActiveSplit() == null) {
        } else {
            index = PigInputFormat.getActiveSplit().getIndex();
        }

        Datum groupName = key.getField(0);
        finalout.group = key;
        finalout.index = index;

        Tuple t = new Tuple(1 + inputCount);
        t.setField(0, groupName);
        for (int i = 1; i < 1 + inputCount; i++) {
            bags[i - 1].clear();
            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++) { // XXX: shouldn't we only do this if INNER flag is set?
            if (t.getBagField(1 + i).size() == 0)
                return;
        }
        //          throw new RuntimeException("combine input: " + t.toString());
        evalPipe.add(t);
        // evalPipe.add(null); // EOF marker
    } catch (Throwable tr) {
        log.error(tr);
        RuntimeException exp = new RuntimeException(tr.getMessage());
        exp.setStackTrace(tr.getStackTrace());
        throw exp;
    }
}

From source file:org.eclipse.jubula.client.ui.rcp.Plugin.java

/**
 * checks if the exception is caused by a known RCP problem
 * @param t the Throwable which was caught in the error handler
 * @return true if the exception was cause by an RCP bug
 *///from www  .j a  v a  2  s  .  c  o  m
public static boolean isRCPException(Throwable t) {
    Throwable work = t;
    do {
        StackTraceElement[] stack = work.getStackTrace();
        for (StackTraceElement el : stack) {
            String className = el.getClassName();
            // check for
            // org.eclipse.ui.views.markers.internal.MarkerAdapter.buildAllMarkers
            if (className.indexOf("MarkerAdapter") != -1) { //$NON-NLS-1$
                return true;
            }
            // double click error in help view
            if (className.indexOf("EngineResultSection") != -1) { //$NON-NLS-1$
                return true;
            }
            // Context Sensitive Help when DSV Cell Editor is open #3291
            if (className.indexOf("ContextHelpPart") != -1) { //$NON-NLS-1$
                return true;
            }
            // http://bugzilla.bredex.de/84 
            if (className.indexOf("CompositeImageDescriptor") != -1) { //$NON-NLS-1$
                return true;
            }
            // http://bugzilla.bredex.de/933 
            if (className.indexOf("EditorStateParticipant") != -1) { //$NON-NLS-1$
                return true;
            }
        }
        // Recursive activation on MacOSX on expand tree item #3618
        String detailMessage = work.getMessage();
        if (detailMessage != null
                && detailMessage.indexOf("WARNING: Prevented recursive attempt to activate part") != -1) { //$NON-NLS-1$
            return true;
        }
        work = work.getCause();
    } while (work != null);
    return false;
}

From source file:com.google.api.ads.adwords.jaxws.extensions.kratu.restserver.AbstractServerResource.java

protected String stackTraceToString(Throwable e) {
    StringBuilder sb = new StringBuilder();
    for (StackTraceElement element : e.getStackTrace()) {
        sb.append(element.toString());//  w  w w  .  java2  s . c  o  m
        sb.append("\n");
    }
    return sb.toString();
}

From source file:org.trianacode.TrianaCloud.Utils.TrianaCloudServlet.java

protected String createStackTrace(Throwable t) {
    StringBuffer stack = new StringBuffer("Message:" + t.getMessage() + "<br/>");
    StackTraceElement[] trace = t.getStackTrace();
    for (StackTraceElement element : trace) {
        stack.append(element.toString()).append("<br/>");
    }//w w w  . j a va 2 s  .  c o  m
    return stack.toString();
}

From source file:org.commonjava.indy.httprox.util.HttpConduitWrapper.java

@Override
public void writeError(final Throwable e) throws IOException {
    final String message = String.format("%s:\n  %s", e.getMessage(),
            StringUtils.join(e.getStackTrace(), "\n  "));

    sinkChannel.write(ByteBuffer.wrap(message.getBytes()));
}

From source file:org.apache.ambari.servicemonitor.reporting.restapi.RestStatusServlet.java

private void doGetProbeStatus(HttpServletRequest req, HttpServletResponse resp, ProbeStatus status)
        throws ServletException, IOException {

    boolean live = status.isSuccess();
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put(LIVE, live);//from w w w  .  j a va 2  s  .c  om
    map.put("timestamp", status.getTimestamp());
    map.put("phase", status.getProbePhase());
    map.put("message", status.getMessage());
    Throwable thrown = status.getThrown();
    if (thrown != null) {
        HashMap<String, Object> tmap = new HashMap<String, Object>();
        tmap.put("message", thrown.toString());
        StackTraceElement[] stackTrace = thrown.getStackTrace();
        int index = 0;
        for (StackTraceElement elt : stackTrace) {
            tmap.put(Integer.toString(index++), elt.toString());
        }
        map.put("exception", tmap);
    }
    writeJSON(resp, map, HttpServletResponse.SC_OK);

}

From source file:com.enonic.cms.web.main.UpgradeController.java

/**
 * Return the formatted cause./*from w  w  w .j a  va 2 s . co m*/
 */
private String getFormattedCause(Throwable cause) {
    StringBuffer str = new StringBuffer();
    str.append("<div class='stacktrace'>");

    for (StackTraceElement elem : cause.getStackTrace()) {
        str.append("<div class='traceelem'>");
        str.append(elem.getClassName()).append(".").append(elem.getMethodName()).append(" (line ");
        str.append(elem.getLineNumber()).append(")");
        str.append("</div>");
    }

    str.append("</div>");
    return str.toString();
}

From source file:org.eclipse.jubula.client.ui.rcp.Plugin.java

/**
 * checks if the exception is caused by a known Content Assist problem
 * @param t the Throwable which was caught in the error handler
 * @return true if the exception was cause by a known Content Assist bug
 */// ww  w  .  j a  v  a 2  s  .  co m
public static boolean isContentAssistException(Throwable t) {

    Throwable work = t;
    do {
        if (work instanceof NullPointerException) {
            StackTraceElement[] stack = work.getStackTrace();
            for (StackTraceElement el : stack) {
                // check for
                // NPE in recomputeProposals
                if (Messages.RecomputeProposals.equals(el.getMethodName())) {
                    return true;
                }
            }
        }
        work = work.getCause();
    } while (work != null);
    return false;
}

From source file:com.infinities.skyport.async.impl.AsyncHandler.java

private Exception throwCause(Exception e, boolean combineStackTraces) throws Exception {
    Throwable cause = e.getCause();
    if (cause == null) {
        throw e;/*from w  w w. j a  v a  2  s .co m*/
    }
    if (combineStackTraces) {
        StackTraceElement[] combined = ObjectArrays.concat(cause.getStackTrace(), e.getStackTrace(),
                StackTraceElement.class);
        cause.setStackTrace(combined);
    }
    if (cause instanceof Exception) {
        throw (Exception) cause;
    }
    if (cause instanceof Error) {
        throw (Error) cause;
    }
    // The cause is a weird kind of Throwable, so throw the outer
    // exception.
    throw e;
}

From source file:com.runwaysdk.logging.RunwayLog.java

public void trace(Object arg0) {
    try {/*from   w w w  . ja  v  a2s  . c om*/
        addSessionIdInfo();
        logger.trace(arg0);
        removeSessionIdInfo();
    } catch (Throwable e) {
        System.err.println(e.getLocalizedMessage());
        System.err.println(e.getStackTrace());
    }
}