Example usage for java.lang Exception getStackTrace

List of usage examples for java.lang Exception getStackTrace

Introduction

In this page you can find the example usage for java.lang Exception getStackTrace.

Prototype

public StackTraceElement[] getStackTrace() 

Source Link

Document

Provides programmatic access to the stack trace information printed by #printStackTrace() .

Usage

From source file:Main.java

public static void printCallPathTop(String text) {
    try {//from   ww w . j  a  v a2  s.c o  m
        throw new Exception(text);
    } catch (Exception e) {
        StackTraceElement[] l = e.getStackTrace();
        System.out.println(
                "DDTrace: [" + e.getLocalizedMessage() + "] " + l[1] + "\n" + l[2] + "\n" + l[l.length - 1]);
    }
}

From source file:x595.Main.java

private static void log(String msg) {
    try {//from   ww w .  j a va  2 s  . c  om
        throw new Exception();
    } catch (Exception e) {
        StackTraceElement head = e.getStackTrace()[1];
        System.out.println("[" + head.getClassName() + "." + head.getMethodName() + "()] > " + msg);
    }
}

From source file:Main.java

/**
 * Gets the stack trace string.//w  w w . j  av  a2s.c om
 *
 * @param e the e
 * @return the stack trace string
 */
public static String getStackTraceString(Exception e) {
    String stackTrace = "";
    for (StackTraceElement l : e.getStackTrace())
        stackTrace += l.toString();
    return stackTrace;
}

From source file:Main.java

/**
 * kill other process and services/* www. j ava  2 s.com*/
 *
 * @param context
 * @return count of clean up process and services
 */
public static int gc(Context context) {
    int count = 0;
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> serviceList = am.getRunningServices(100);
    if (serviceList != null) {
        for (ActivityManager.RunningServiceInfo service : serviceList) {
            if (service.pid == android.os.Process.myPid())
                continue;
            try {
                android.os.Process.killProcess(service.pid);
                count++;
            } catch (Exception e) {
                e.getStackTrace();
            }
        }
    }

    List<ActivityManager.RunningAppProcessInfo> processList = am.getRunningAppProcesses();
    if (processList != null) {
        for (ActivityManager.RunningAppProcessInfo process : processList) {
            if (process.importance > ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
                String[] pkgList = process.pkgList;
                for (String pkgName : pkgList) {
                    try {
                        am.killBackgroundProcesses(pkgName);
                        count++;
                    } catch (Exception e) {
                        e.getStackTrace();
                    }
                }
            }
        }
    }
    return count;
}

From source file:Main.java

/**
 * Prints your current certificate signature to the Logcat. Use this method to obtain your certificate signature.
 *
 * @param context The application context.
 *///from w  w w.j a  v a 2s .c  o m

public static void getCertificateSignature(Context context) {
    try {
        PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(),
                PackageManager.GET_SIGNATURES);

        // The APK is signed with multiple signatures, probably it was tampered.
        if (packageInfo.signatures.length > 1) {
            return;
        }

        for (Signature signature : packageInfo.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");

            md.update(signature.toByteArray());

            Log.d("TAMPERING_PROTECTION", "**" + Base64.encodeToString(md.digest(), Base64.DEFAULT) + "**");
        }
    } catch (Exception exception) {
        Log.d("TAMPERING_PROTECTION", exception.getStackTrace().toString());
    }
}

From source file:Main.java

public static int gc(Context cxt) {
    //long i = getDeviceUsableMemory(cxt);
    int count = 0;
    ActivityManager am = (ActivityManager) cxt.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> serviceList = am.getRunningServices(100);
    if (serviceList != null)
        for (RunningServiceInfo service : serviceList) {
            if (service.pid == android.os.Process.myPid())
                continue;
            try {
                android.os.Process.killProcess(service.pid);
                count++;/*ww  w  . j a v a 2  s  . c o m*/
            } catch (Exception e) {
                e.getStackTrace();
                //continue;
            }
        }

    List<RunningAppProcessInfo> processList = am.getRunningAppProcesses();
    if (processList != null)
        for (RunningAppProcessInfo process : processList) {
            if (process.importance > RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
                String[] pkgList = process.pkgList;
                for (String pkgName : pkgList) {
                    try {
                        am.killBackgroundProcesses(pkgName);
                        count++;
                    } catch (Exception e) {
                        e.getStackTrace();
                        //continue;
                    }
                }
            }
        }
    return count;
}

From source file:Main.java

public static int gc(Context cxt) {
    //long i = getDeviceUsableMemory(cxt);
    int count = 0;
    ActivityManager am = (ActivityManager) cxt.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> serviceList = am.getRunningServices(100);
    if (serviceList != null)
        for (RunningServiceInfo service : serviceList) {
            if (service.pid == android.os.Process.myPid())
                continue;
            try {
                android.os.Process.killProcess(service.pid);
                count++;//from w  ww.j  a va 2  s.co m
            } catch (Exception e) {
                e.getStackTrace();
                continue;
            }
        }

    List<RunningAppProcessInfo> processList = am.getRunningAppProcesses();
    if (processList != null)
        for (RunningAppProcessInfo process : processList) {
            if (process.importance > RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
                String[] pkgList = process.pkgList;
                for (String pkgName : pkgList) {
                    try {
                        am.killBackgroundProcesses(pkgName);
                        count++;
                    } catch (Exception e) {
                        e.getStackTrace();
                        continue;
                    }
                }
            }
        }
    return count;
}

From source file:de.uni_potsdam.hpi.bpt.promnicat.parser.test.EpcParserTest.java

/**
 * start BPM AI importer// w w w.j a  v  a  2 s  . c o m
 */
@BeforeClass
public static void setUp() {
    try {
        importModels(new File("resources/BPMAI/model_epc0"));
    } catch (Exception e) {
        fail("Unexpected exception during model import: " + e.getStackTrace().toString());
    }

}

From source file:deodex.tools.ZipTools.java

/**
 * check if the given fileName matches a file in the given zipFile
 * without extraction ,file name can contain full paths in zip like
 * '/path/myFile.txt //  ww w  .ja  v a  2s .c o  m
 * @param fileName file name to search fot
 * @param zipFile the zip in which we will search for the file 
 * @return isFileFound returns true is a file matches the given file 
 */
public static boolean isFileinZipFailSafe(String fileName, java.util.zip.ZipFile zipFile) {
    try {

        Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();

        while (zipEntries.hasMoreElements()) {

            if (zipEntries.nextElement().getName().contains(fileName)) {
                return true;
            }
        }

    } catch (Exception e) {
        Logger.appendLog("[ZipTools][EX]" + e.getStackTrace());
        return false;
    }
    return false;
}

From source file:de.tudarmstadt.ukp.clarin.webanno.api.dao.DebugUtils.java

public static void smallStack(int aLimit) {
    StringBuilder sb = new StringBuilder();
    Exception e = new RuntimeException();
    boolean reqNewLine = true;
    boolean firstSkipped = false;
    int count = 0;
    for (StackTraceElement f : e.getStackTrace()) {
        if (!firstSkipped) {
            firstSkipped = true;//from   w ww.j a  v a  2 s .  c om
            continue;
        }
        if (f.getClassName().startsWith("de.tudarmstadt")) {
            if (reqNewLine) {
                sb.append("\n");
            }
            sb.append(f);
            count++;
        } else {
            sb.append(".");
            reqNewLine = true;
        }
        if (aLimit > 0 && count >= aLimit) {
            break;
        }
    }
    LOG.debug(sb);
}