Here you can find the source of getStackTrace(final Throwable error)
Parameter | Description |
---|---|
error | error to be converted to String. |
public static String getStackTrace(final Throwable error)
//package com.java2s; /*//from w ww.ja v a 2 s. c o m * ======================================================================== * * Codehaus CARGO, copyright 2004-2011 Vincent Massol, 2012-2018 Ali Tokmen. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * ======================================================================== */ import java.io.IOException; import java.io.StringWriter; public class Main { /** * Returns error stacktrace as a String. * @param error error to be converted to String. * @return error stacktrace */ public static String getStackTrace(final Throwable error) { StringWriter writer = new StringWriter(); for (StackTraceElement element : error.getStackTrace()) { writer.write(element.toString()); } try { return writer.toString(); } finally { try { writer.close(); } catch (IOException ex) { //nothing to do here. } } } }