Java Throwable to StackTrace getStackTrace(Throwable t, String[] allow, String[] deny)

Here you can find the source of getStackTrace(Throwable t, String[] allow, String[] deny)

Description

Returns stack trace filtered by class names.

License

Open Source License

Declaration

public static StackTraceElement[] getStackTrace(Throwable t, String[] allow, String[] deny) 

Method Source Code

//package com.java2s;

import java.util.ArrayList;

public class Main {
    /**// w  ww. j  av  a2  s .  c o  m
     * Returns stack trace filtered by class names.
     */
    public static StackTraceElement[] getStackTrace(Throwable t, String[] allow, String[] deny) {
        StackTraceElement[] st = t.getStackTrace();
        ArrayList<StackTraceElement> result = new ArrayList<>(st.length);

        elementLoop: for (StackTraceElement element : st) {
            String className = element.getClassName();
            if (allow != null) {
                boolean validElemenet = false;
                for (String filter : allow) {
                    if (className.indexOf(filter) != -1) {
                        validElemenet = true;
                        break;
                    }
                }
                if (validElemenet == false) {
                    continue;
                }
            }
            if (deny != null) {
                for (String filter : deny) {
                    if (className.indexOf(filter) != -1) {
                        continue elementLoop;
                    }
                }
            }
            result.add(element);
        }
        st = new StackTraceElement[result.size()];
        return result.toArray(st);
    }
}

Related

  1. cleanup(StackTraceElement[] stack)
  2. getStackTraceChain(Throwable t, String[] allow, String[] deny)
  3. getStackTraces(Throwable throwable)