Example usage for java.lang StackTraceElement getLineNumber

List of usage examples for java.lang StackTraceElement getLineNumber

Introduction

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

Prototype

public int getLineNumber() 

Source Link

Document

Returns the line number of the source line containing the execution point represented by this stack trace element.

Usage

From source file:edu.usu.sdl.openstorefront.common.util.StringProcessor.java

/**
 * This will produce html highlighted stacktrace
 *
 * @param throwable// w  w  w  .  jav  a2 s  .  c om
 * @return
 */
public static String parseStackTraceHtml(Throwable throwable) {
    StringBuilder exception = new StringBuilder();

    if (throwable != null) {
        String message = throwable.getMessage();
        if (StringUtils.isNotBlank(message)) {
            exception.append("<b>Message:</b> <span style='color: red;'><b>")
                    .append(message.replace("\n", "<br>")).append("</b><br>");
        }
        for (StackTraceElement stackTraceElement : throwable.getStackTrace()) {
            String style = "color: grey; font-size: 10px;";
            if (stackTraceElement.getClassName().contains("edu.usu.sdl")) {
                style = "color: black; font-size: 12px; font-wieght: bold;";
            }
            exception.append("<span style='").append(style).append("'>")
                    .append(stackTraceElement.getClassName()).append(" (")
                    .append(stackTraceElement.getMethodName()).append(") : ")
                    .append(stackTraceElement.getLineNumber()).append(" ").append("</span><br>");
        }
        if (throwable.getSuppressed().length > 0) {
            exception.append("Suppress Exceptions: ");
            for (Throwable suppressed : throwable.getSuppressed()) {
                exception.append(parseStackTraceHtml(suppressed)).append("<br>");
            }
        }

        if (throwable.getCause() != null) {

        }
    }

    return exception.toString();
}

From source file:de.madvertise.android.sdk.MadvertiseUtil.java

static void logMessage(final String tag, final int level, String message, Throwable throwable,
        StackTraceElement stackTraceElement) {
    String logTag = tag;/*from  www  .  jav a2s .  c  om*/
    if (!PRINT_LOG) {
        return;
    }

    if (tag == null) {
        logTag = MadvertiseUtil.LOG;
    }

    if (message == null) {
        message = "";
    }

    String fullClassName = stackTraceElement.getClassName();
    String className = fullClassName.substring(fullClassName.lastIndexOf(".") + 1);
    int lineNumber = stackTraceElement.getLineNumber();

    String logMessage = "(" + className + ":" + lineNumber + ") : " + message;
    if (throwable != null) {
        logMessage += '\n' + Log.getStackTraceString(throwable);
    }
    Log.println(level, logTag, logMessage);
}

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. ja 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:eu.faircode.adblocker.Util.java

public static void sendCrashReport(Throwable ex, final Context context) {
    if (!isPlayStoreInstall(context))
        return;//ww  w. ja  v a  2  s  . c o  m

    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.egt.core.aplicacion.Bitacora.java

public static void stack() {
    boolean b = true;
    StackTraceElement[] stack = Thread.currentThread().getStackTrace();
    for (StackTraceElement trace : stack) {
        if (trace.getClassName().startsWith(PREFIJO_PAQUETE)) {
            if (trace.getClassName().equals(Bitacora.class.getName())) {
                continue;
            } else if (b) {
                b = false;//from   w  w w . j a v a 2s.  c  o m
                logTrace(trace.getClassName() + "." + trace.getMethodName() + ":" + trace.getLineNumber());
            } else {
                logTrace("..." + getStackTraceElementTrack(trace));
            }
        }
    }
}

From source file:org.eclipse.epp.internal.logging.aeri.ui.model.Reports.java

public static Throwable newThrowable(java.lang.Throwable throwable) {
    Throwable mThrowable = factory.createThrowable();
    mThrowable.setMessage(throwable.getMessage());
    mThrowable.setClassName(throwable.getClass().getName());
    List<StackTraceElement> mStackTrace = mThrowable.getStackTrace();
    for (java.lang.StackTraceElement stackTraceElement : throwable.getStackTrace()) {
        StackTraceElement mStackTraceElement = factory.createStackTraceElement();
        mStackTraceElement.setFileName(stackTraceElement.getFileName());
        mStackTraceElement.setClassName(ensureNotBlank(stackTraceElement.getClassName(), throwable));
        mStackTraceElement.setMethodName(ensureNotBlank(stackTraceElement.getMethodName(), throwable));
        mStackTraceElement.setLineNumber(stackTraceElement.getLineNumber());
        mStackTraceElement.setNative(stackTraceElement.isNativeMethod());
        mStackTrace.add(mStackTraceElement);
    }//w w  w .  ja va  2 s  .c o m
    java.lang.Throwable cause = throwable.getCause();
    if (cause != null) {
        if (cause == throwable) {
            log(WARN_CYCLIC_EXCEPTION, cause.toString());
            return mThrowable;
        }
        mThrowable.setCause(newThrowable(cause));
    }
    return mThrowable;
}

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

public static void sendCrashReport(Throwable ex, final Context context) {
    if (!isPlayStoreInstall(context))
        return;/*from   w w  w  .  jav  a 2 s .  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:free.yhc.feeder.model.Utils.java

private static void log(Class<?> cls, LogLV lv, String msg) {
    if (null == msg)
        return;/*from  www  .j av a2s . c om*/

    StackTraceElement ste = Thread.currentThread().getStackTrace()[5];
    msg = ste.getClassName() + "/" + ste.getMethodName() + "(" + ste.getLineNumber() + ") : " + msg;

    if (ENABLE_LOGF) {
        try {
            sLogout.write(lv.pref + " " + msg + "\n");
            sLogout.flush();
        } catch (IOException e) {
        }
    } else {
        switch (lv) {
        case V:
            Log.v(cls.getSimpleName(), msg);
            break;
        case D:
            Log.d(cls.getSimpleName(), msg);
            break;
        case I:
            Log.i(cls.getSimpleName(), msg);
            break;
        case W:
            Log.w(cls.getSimpleName(), msg);
            break;
        case E:
            Log.e(cls.getSimpleName(), msg);
            break;
        case F:
            Log.wtf(cls.getSimpleName(), msg);
            break;
        }
    }
}

From source file:tools.datasync.db2db.util.ExceptionHandler.java

public void handle(Throwable ex, Level level, String message, Object... params) {

    // TODO: Log all caused by messages also...
    // TODO: Search tools.datasync.db2db package method and log 'at' here...
    StackTraceElement[] stackTraceElements = ex.getStackTrace();
    StackTraceElement top = stackTraceElements[0];

    String clazz = top.getClassName();
    String method = top.getMethodName();
    int line = top.getLineNumber();

    StringBuffer sb = new StringBuffer();
    sb.append(clazz);//from  w  w w .j  a v a 2  s.co  m
    sb.append('.');
    sb.append(method);
    sb.append('(');
    sb.append(line);
    sb.append(") : ");
    sb.append(message);
    sb.append(". ");
    sb.append(ex.getMessage());
    sb.append('\n');

    logger.log(level, sb.toString());
}

From source file:com.github.pjungermann.config.specification.dsl.groovy.SpecificationDSLInterpreter.java

protected int getCurrentLine() {
    for (final StackTraceElement element : new Exception().getStackTrace()) {
        if (element.getFileName().equals(source.getName())) {
            return element.getLineNumber();
        }/*from  w  w w. j  a  v a 2 s  .  c  o  m*/
    }

    return -1;
}