Example usage for java.lang StackTraceElement getMethodName

List of usage examples for java.lang StackTraceElement getMethodName

Introduction

In this page you can find the example usage for java.lang StackTraceElement getMethodName.

Prototype

public String getMethodName() 

Source Link

Document

Returns the name of the method containing the execution point represented by this stack trace element.

Usage

From source file:android_network.hetnet.vpn_service.Util.java

public static void sendCrashReport(Throwable ex, final Context context) {
    if (!isPlayStoreInstall(context) || Util.isDebuggable(context))
        return;//from  w  w  w  . j a  v a2 s . c  om

    try {
        ApplicationErrorReport report = new ApplicationErrorReport();
        report.packageName = report.processName = context.getPackageName();
        report.time = System.currentTimeMillis();
        report.type = ApplicationErrorReport.TYPE_CRASH;
        report.systemApp = false;

        ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo();
        crash.exceptionClassName = ex.getClass().getSimpleName();
        crash.exceptionMessage = ex.getMessage();

        StringWriter writer = new StringWriter();
        PrintWriter printer = new PrintWriter(writer);
        ex.printStackTrace(printer);

        crash.stackTrace = writer.toString();

        StackTraceElement stack = ex.getStackTrace()[0];
        crash.throwClassName = stack.getClassName();
        crash.throwFileName = stack.getFileName();
        crash.throwLineNumber = stack.getLineNumber();
        crash.throwMethodName = stack.getMethodName();

        report.crashInfo = crash;

        final Intent bug = new Intent(Intent.ACTION_APP_ERROR);
        bug.putExtra(Intent.EXTRA_BUG_REPORT, report);
        bug.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (bug.resolveActivity(context.getPackageManager()) != null)
            context.startActivity(bug);
    } catch (Throwable exex) {
        Log.e(TAG, exex.toString() + "\n" + Log.getStackTraceString(exex));
    }
}

From source file:com.chiorichan.factory.ScriptTraceElement.java

public ScriptTraceElement(ScriptingContext context, StackTraceElement ste) {
    this.context = context;
    fileName = ste.getFileName();//from  w w w.  j  a  v  a  2  s  .  c  om
    methodName = ste.getMethodName();
    className = ste.getClassName();
    lineNum = ste.getLineNumber();
    colNum = -1;
}

From source file:eu.faircode.adblocker.Util.java

public static void sendCrashReport(Throwable ex, final Context context) {
    if (!isPlayStoreInstall(context))
        return;// w  w  w.  j  ava2 s.  c om

    try {
        ApplicationErrorReport report = new ApplicationErrorReport();
        report.packageName = report.processName = context.getPackageName();
        report.time = System.currentTimeMillis();
        report.type = ApplicationErrorReport.TYPE_CRASH;
        report.systemApp = false;

        ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo();
        crash.exceptionClassName = ex.getClass().getSimpleName();
        crash.exceptionMessage = ex.getMessage();

        StringWriter writer = new StringWriter();
        PrintWriter printer = new PrintWriter(writer);
        ex.printStackTrace(printer);

        crash.stackTrace = writer.toString();

        StackTraceElement stack = ex.getStackTrace()[0];
        crash.throwClassName = stack.getClassName();
        crash.throwFileName = stack.getFileName();
        crash.throwLineNumber = stack.getLineNumber();
        crash.throwMethodName = stack.getMethodName();

        report.crashInfo = crash;

        final Intent bug = new Intent(Intent.ACTION_APP_ERROR);
        bug.putExtra(Intent.EXTRA_BUG_REPORT, report);
        bug.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (bug.resolveActivity(context.getPackageManager()) != null)
            context.startActivity(bug);
    } catch (Throwable exex) {
        Log.e(TAG, exex.toString() + "\n" + Log.getStackTraceString(exex));
    }
}

From source file:es.bsc.servicess.ide.Logger.java

private String printInvocationInfo(StackTraceElement invoker) {
    return "[" + invoker.getClassName() + "." + invoker.getMethodName() + "(" + invoker.getFileName() + ":"
            + invoker.getLineNumber() + ")]";
}

From source file:edu.cornell.mannlib.vitro.webapp.utils.developer.loggers.StackTraceUtility.java

private String assembleCallStackString() {
    StringBuilder stack = new StringBuilder();
    for (StackTraceElement ste : stackTrace) {
        stack.append(ste.getClassName()).append(" ").append(ste.getMethodName()).append(" ");
    }/*from   w  w w  . j  a  va  2s.  c  o m*/
    return stack.deleteCharAt(stack.length() - 1).toString();
}

From source file:com.master.metehan.filtereagle.Util.java

public static void sendCrashReport(Throwable ex, final Context context) {
    if (!isPlayStoreInstall(context))
        return;/* w  ww.jav a2s. c o  m*/
    if (!(Util.isDebuggable(context) || Util.getSelfVersionName(context).contains("beta")))
        return;

    try {
        ApplicationErrorReport report = new ApplicationErrorReport();
        report.packageName = report.processName = context.getPackageName();
        report.time = System.currentTimeMillis();
        report.type = ApplicationErrorReport.TYPE_CRASH;
        report.systemApp = false;

        ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo();
        crash.exceptionClassName = ex.getClass().getSimpleName();
        crash.exceptionMessage = ex.getMessage();

        StringWriter writer = new StringWriter();
        PrintWriter printer = new PrintWriter(writer);
        ex.printStackTrace(printer);

        crash.stackTrace = writer.toString();

        StackTraceElement stack = ex.getStackTrace()[0];
        crash.throwClassName = stack.getClassName();
        crash.throwFileName = stack.getFileName();
        crash.throwLineNumber = stack.getLineNumber();
        crash.throwMethodName = stack.getMethodName();

        report.crashInfo = crash;

        final Intent bug = new Intent(Intent.ACTION_APP_ERROR);
        bug.putExtra(Intent.EXTRA_BUG_REPORT, report);
        bug.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (bug.resolveActivity(context.getPackageManager()) != null)
            context.startActivity(bug);
    } catch (Throwable exex) {
        Log.e(TAG, exex.toString() + "\n" + Log.getStackTraceString(exex));
    }
}

From source file:gumga.framework.application.GumgaLoggerService.java

public String createLogLine(String msg, int level) {
    StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[level];
    String line = sdf.format(new Date()) + " " + stackTraceElement.getClassName() + " "
            + stackTraceElement.getMethodName() + " " + stackTraceElement.getLineNumber() + " " + msg + "\n";
    return line;//from  ww  w.  j a v  a  2 s . c o m

}

From source file:edu.cornell.mannlib.vitro.webapp.utils.developer.loggers.StackTraceUtility.java

public String format(boolean requested) {
    StringBuilder sb = new StringBuilder();
    if (requested) {
        for (StackTraceElement ste : stackTrace) {
            sb.append(String.format("   %s.%s(%s:%d) \n", ste.getClassName(), ste.getMethodName(),
                    ste.getFileName(), ste.getLineNumber()));
        }/*from www .j ava 2  s. c  o  m*/
        sb.append("   ...\n");
    }
    return sb.toString();
}

From source file:io.gumga.application.GumgaLoggerService.java

/**
 *
 * @param msg mensagem do log/* w w  w .ja v  a  2s.com*/
 * @param level index da execption do StrackTrace
 * @return dados do log
 */
public String createLogLine(String msg, int level) {
    StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[level];
    String line = sdf.format(new Date()) + " " + stackTraceElement.getClassName() + " "
            + stackTraceElement.getMethodName() + " " + stackTraceElement.getLineNumber() + " " + msg + "\n";
    return line;

}

From source file:org.apache.flink.client.cli.CliFrontend.java

/**
 * Displays an exception message.//w  w w.  j a  v a 2  s .c o m
 *
 * @param t The exception to display.
 * @return The return code for the process.
 */
private static int handleError(Throwable t) {
    LOG.error("Error while running the command.", t);

    System.err.println();
    System.err.println("------------------------------------------------------------");
    System.err.println(" The program finished with the following exception:");
    System.err.println();

    if (t.getCause() instanceof InvalidProgramException) {
        System.err.println(t.getCause().getMessage());
        StackTraceElement[] trace = t.getCause().getStackTrace();
        for (StackTraceElement ele : trace) {
            System.err.println("\t" + ele);
            if (ele.getMethodName().equals("main")) {
                break;
            }
        }
    } else {
        t.printStackTrace();
    }
    return 1;
}