Java Stacktrace to String stackTraceContains(String... needles)

Here you can find the source of stackTraceContains(String... needles)

Description

Determines whether the current stack trace contains the specified string.

License

Open Source License

Parameter

Parameter Description
needles the text(s) to find

Return

whether the stack trace contains the text

Declaration

static boolean stackTraceContains(String... needles) 

Method Source Code

//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;
    }
}

Related

  1. getStackTraceString(Exception e)
  2. stackTrace()
  3. stacktrace()
  4. stacktrace2string(StackTraceElement[] stackTraceElements)
  5. stackTraceAsString(Exception ex)
  6. stackTraceStr(Exception e)
  7. stackTraceString(Throwable t)
  8. stackTraceToString(Exception e)
  9. stackTraceToString(Exception e, int nBack)