Here you can find the source of stackTrace(Throwable th, String pattern)
Parameter | Description |
---|---|
th | a parameter |
p | a parameter |
public static String stackTrace(Throwable th, String pattern)
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.PrintWriter; import java.io.StringReader; import java.io.StringWriter; public class Main { /**/* ww w. j av a2 s .c o m*/ * Return the Stacktrace as String * Optional filter every line with Pattern String * @param th * @param p * @return */ public static String stackTrace(Throwable th, String pattern) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); th.printStackTrace(pw); if (pattern != null) { BufferedReader br = new BufferedReader(new StringReader(sw.toString())); sw = new StringWriter(); String s = null; try { while ((s = br.readLine()) != null) { if (s.matches(pattern)) sw.write(s + "\n"); } } catch (Exception e) { } } return sw.toString(); } }