Java Throwable to String formatException(Throwable t)

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

Description

format Exception

License

Open Source License

Declaration

public static String formatException(Throwable t) 

Method Source Code


//package com.java2s;
/*/*from  www .ja  va 2s.co  m*/
 * Copyright (c) 2007-2013, 2015 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Eike Stepper - initial API and implementation
 */

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

public class Main {
    /**
     * @since 2.0
     */
    public static String formatException(Throwable t) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintStream s = new PrintStream(baos);
        t.printStackTrace(s);
        return baos.toString();
    }
}

Related

  1. formatException(Throwable e)
  2. formatException(Throwable t)
  3. formatExceptionForDisplay(Exception e)
  4. formatThrowableForHtml(Throwable t)
  5. formatThrown(final Throwable thrown)