Java Throwable to String getExceptionStackTrace(Throwable exception)

Here you can find the source of getExceptionStackTrace(Throwable exception)

Description

get Exception Stack Trace

License

Apache License

Declaration

public static String getExceptionStackTrace(Throwable exception) 

Method Source Code


//package com.java2s;
/*/* ww  w.ja va  2s.c o  m*/
 * Copyright 2001-2013 Geert Bevin (gbevin[remove] at uwyn dot com)
 * Licensed under the Apache License, Version 2.0 (the "License")
 */

import java.io.PrintWriter;
import java.io.StringWriter;

public class Main {
    public static String getExceptionStackTrace(Throwable exception) {
        if (null == exception)
            throw new IllegalArgumentException("exception can't be null;");

        String stack_trace;

        StringWriter string_writer = new StringWriter();
        try (PrintWriter print_writer = new PrintWriter(string_writer)) {
            exception.printStackTrace(print_writer);
            stack_trace = string_writer.getBuffer().toString();
        }

        return stack_trace;
    }
}

Related

  1. getExceptionPrintout(Throwable aThrowable)
  2. getExceptionStack(final Throwable e)
  3. getExceptionStack(Throwable e)
  4. getExceptionStackTrace(Throwable ex)
  5. getExceptionStackTrace(Throwable exception)
  6. getExceptionString(Throwable e)
  7. getExceptionString(Throwable t)
  8. getExceptionString(Throwable throwable)
  9. getExceptionText(Throwable e)