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:com.opengamma.engine.calcnode.MutableExecutionLog.java

public void setException(Throwable exception) {
    _exceptionClass = exception.getClass().getName();
    _exceptionMessage = exception.getMessage();
    final StringBuilder buffer = new StringBuilder();
    for (StackTraceElement element : exception.getStackTrace()) {
        buffer.append(element.toString()).append("\n");
    }//from  w w w.ja  v a  2  s .c  om
    _exceptionStackTrace = buffer.toString();
    _logLevels.add(LogLevel.WARN);
}

From source file:org.apache.ode.utils.DOMUtils.java

private static void throwIOException(Throwable t) throws IOException {
    IOException e = new IOException(t.getMessage());
    e.setStackTrace(t.getStackTrace());
    throw e;//from w  w  w  . j av a  2  s .  c  o m
}

From source file:org.LexGrid.LexBIG.caCore.client.proxy.LexEVSApplicationServiceProxy.java

public static Exception digOutRealExceptionAndThrowIt(Exception e) throws Exception {
    Throwable lbiEx = null;
    Throwable next = null;/*from   www  . ja  v  a2 s . c  o m*/
    Throwable cur = e;
    boolean lexBigExceptionFound = false;
    boolean done = false;
    int i = 1;
    int max = 500; // a limit so we won't ever be in endless loop
    if (isLexBigException(cur) == true) {
        lexBigExceptionFound = true;
        lbiEx = cur;
    }
    while (!done) {
        next = cur.getCause();
        ++i;
        if (next == null) {
            done = true;
        } else {
            cur = next;
            if (isLexBigException(cur) == true) {
                lexBigExceptionFound = true;
                lbiEx = cur;
            }
            if (i == max) {
                done = true;
                log.error("digOutRealExceptionAndThrowIt: reached max depth of: " + max);
            }
        }
    }
    Exception returnException = null;
    if (lexBigExceptionFound == true) {
        returnException = new LBException(lbiEx.getMessage());
        returnException.setStackTrace(lbiEx.getStackTrace());
    } else {
        returnException = e;
    }
    return returnException;
}

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./*from  w w w  .  j av  a  2s .  co 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:de.unisb.cs.st.javalanche.rhino.RhinoTestRunnable.java

public void run() {
    List<String> argList = getArgs();
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final ByteArrayOutputStream err = new ByteArrayOutputStream();

    String[] arguments = argList.toArray(new String[0]);
    try {/* w  w w .  ja va  2 s  .  c  o  m*/
        stopWatch.start();
        exitCode = WrappedMain.wrappedExec(arguments, new PrintStream(out), new PrintStream(err));

    } catch (Throwable t) {
        String message = "Caught exception during mutation testing. Exception is most probably caused by the mutation";
        logger.warn(message, t);
        logger.warn(t.toString() + " " + Arrays.toString(t.getStackTrace()));
        exitCode = -1;
    } finally {
        stopWatch.stop();
    }
    byte[] outByteArray = out.toByteArray();
    outString = new String(outByteArray);
    byte[] errByteArray = err.toByteArray();
    errString = new String(errByteArray);
    synchronized (this) {
        hasRun = true;
    }
    logger.info("Runnable finsihed  Took " + DurationFormatUtils.formatDurationHMS(stopWatch.getTime())
            + " \nOUT:\n" + outString + " \nERR\n" + errString);
}

From source file:org.biokoframework.http.exception.impl.ExceptionResponseBuilderImpl.java

private String descriptionOf(Throwable throwable) {
    StringBuilder message = new StringBuilder().append(throwable.getClass().getName());
    if (!StringUtils.isEmpty(throwable.getMessage())) {
        message.append(" with message '").append(throwable.getMessage()).append("'");
    }//  w w  w .ja v  a 2 s  . c o  m
    message.append(" [").append(throwable.getStackTrace()[0]).append("]");
    if (throwable.getCause() != null) {
        message.append(" Caused by " + descriptionOf(throwable.getCause()));
    }
    return message.toString();
}

From source file:org.exist.xquery.XQueryUseCase.java

protected void processQueries(File file) throws Exception {
    File[] files = file.listFiles(new FileFilter() {
        public boolean accept(File pathname) {
            return pathname.getName().startsWith("q") && pathname.getName().endsWith(".xq");
        }//from   ww w.j  a  v a  2s  .  co  m
    });
    for (int i = 0; i < files.length; i++) {
        System.out.println("processing use-case: " + files[i].getAbsolutePath());
        System.out.println("========================================================================");
        String query = readQuery(files[i]);
        System.out.println(query);
        System.out.println("_________________________________________________________________________________");
        XQueryService service = (XQueryService) root.getService("XQueryService", "1.0");
        ResourceSet results;
        try {
            results = service.query(query);
            for (int j = 0; j < results.getSize(); j++) {
                String output = (String) results.getResource(j).getContent();
                System.out.println(output);
            }
        } catch (Exception e) {
            Throwable cause = e.getCause();
            if (cause == null)
                cause = e;
            System.err.println("Exception: " + e.getClass() + " - " + cause);
            for (int j = 0; j < 4; j++) {
                StackTraceElement el = cause.getStackTrace()[j];
                System.err.println(el);
            }
            e.getStackTrace();
            // rethrow for JUnit reporting
            throw e;
        }
        System.out.println("========================================================================");
    }
}

From source file:org.jetbrains.webdemo.executors.ThrowableSerializer.java

@Override
public void serialize(Throwable throwable, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
        throws IOException, JsonProcessingException {
    jsonGenerator.writeStartObject();//from www. j a v  a  2  s  . c om
    jsonGenerator.writeStringField("message", throwable.getMessage());
    jsonGenerator.writeStringField("fullName", throwable.getClass().getName());
    jsonGenerator.writeObjectField("stackTrace", throwable.getStackTrace());
    jsonGenerator.writeObjectField("cause", throwable.getCause() != throwable ? throwable.getCause() : null);
    jsonGenerator.writeEndObject();
}

From source file:com.example.GWTOAuthLoginDemo.server.rpc.OAuthLoginServiceImpl.java

public static String stackTraceToString(Throwable caught) {
    StringBuilder sb = new StringBuilder();
    for (StackTraceElement e : caught.getStackTrace()) {
        sb.append(e.toString()).append("\n");
    }/*from   w w  w . jav  a 2 s .c  om*/
    return sb.toString();
}

From source file:net.ymate.platform.log.AbstractLogger.java

/**
 * ?//from   w w w. j av a 2  s . co m
 *
 * @param e ?
 * @return ??
 */
protected String __doMakeStackInfo(Throwable e) {
    if (e == null) {
        return StringUtils.EMPTY;
    }
    StringBuilder _stackSB = new StringBuilder(e.getClass().getName()).append(": ").append(StringUtils.EMPTY)
            .append(StringUtils.trimToEmpty(e.getMessage())).append("\n");
    StackTraceElement[] _stacks = e.getStackTrace();
    for (StackTraceElement _stack : _stacks) {
        _stackSB.append("\tat ") // 
                .append(_stack).append("\n");
    }
    __ex(_stackSB, e.getCause());
    return _stackSB.toString();
}