Java Throwable to String stackToString(Throwable t)

Here you can find the source of stackToString(Throwable t)

Description

Writes a throwed exception to a string for streaming to the server

License

Open Source License

Parameter

Parameter Description
t a parameter

Declaration

public static String stackToString(Throwable t) 

Method Source Code


//package com.java2s;
/*/*from ww  w . ja  va2 s . co m*/
 * This file is part of ErrorReporter
 * The MIT License (MIT)
 *
 * Copyright (c) 2014 David
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

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

public class Main {
    /**
     * Writes a throwed exception to a string for streaming to the server
     * @param t
     * @return
     */
    public static String stackToString(Throwable t) {
        Writer result = new StringWriter();
        PrintWriter printWriter = new PrintWriter(result);
        t.printStackTrace(printWriter);
        return result.toString();
    }
}

Related

  1. serializeStackTrace(Throwable th)
  2. stackToString(Exception e)
  3. stackToString(Throwable e)
  4. stackToString(Throwable e)
  5. stackToString(Throwable e)
  6. stackToString(Throwable throwable, boolean skipMessage)
  7. stackTrace(final Throwable t)
  8. stacktrace(Logger logger, Throwable ex)
  9. stackTrace(Throwable cause)