Here you can find the source of stackTraceContains(String... needles)
Parameter | Description |
---|---|
needles | the text(s) to find |
static boolean stackTraceContains(String... needles)
//package com.java2s; import java.io.PrintWriter; import java.io.StringWriter; public class Main { /**//w w w. j ava2 s. c o m * Determines whether the current stack trace contains the specified string. * * @param needles the text(s) to find * @return whether the stack trace contains the text */ static boolean stackTraceContains(String... needles) { final StringWriter writer = new StringWriter(); final PrintWriter out = new PrintWriter(writer); new Exception().printStackTrace(out); out.close(); final String haystack = writer.toString(); for (final String needle : needles) { if (haystack.contains(needle)) return true; } return false; } }