Java Throwable to String getExceptionHeadline(Throwable t)

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

Description

get Exception Headline

License

BSD License

Declaration

public static String getExceptionHeadline(Throwable t) 

Method Source Code


//package com.java2s;
//License from project: BSD License 

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static String getExceptionHeadline(Throwable t) {
        Pattern pattern = Pattern.compile("([\\w\\.]+)(:.*)?");
        String stackTrace = getStackTrace(t);
        Matcher matcher = pattern.matcher(stackTrace);

        if (matcher.find())
            return matcher.group(1);

        return null;
    }// www. j  a  v  a 2  s .co m

    public static String getStackTrace(Throwable t) {
        if (t == null)
            return null;

        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        t.printStackTrace(pw);
        return sw.toString();
    }
}

Related

  1. getErrorMessage(Throwable e)
  2. getExceptionAsString(Throwable _ex)
  3. getExceptionDescription(Throwable e)
  4. getExceptionDetails (final Throwable e)
  5. getExceptionDetails(Throwable throwable)
  6. getExceptionPrintout(Throwable aThrowable)
  7. getExceptionStack(final Throwable e)
  8. getExceptionStack(Throwable e)
  9. getExceptionStackTrace(Throwable ex)