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:Main.java

public static final String formatStackTrace(final StackTraceElement pStackTraceElement) {
    return new StringBuilder().append(pStackTraceElement.getClassName()).append('.')
            .append(pStackTraceElement.getMethodName()).append('(').append(pStackTraceElement.getFileName())
            .append(':').append(pStackTraceElement.getLineNumber()).append(')').toString();
}

From source file:com.cloud.utils.ProcessUtil.java

public static String dumpStack() {
    StringBuilder sb = new StringBuilder();
    StackTraceElement[] elems = Thread.currentThread().getStackTrace();
    if (elems != null && elems.length > 0) {
        for (StackTraceElement elem : elems) {
            sb.append("\tat ").append(elem.getMethodName()).append("(").append(elem.getFileName()).append(":")
                    .append(elem.getLineNumber()).append(")\n");
        }//from  w ww .  j  a  v  a2 s. c o  m
    }
    return sb.toString();
}

From source file:com.clustercontrol.selfcheck.monitor.ThreadActivityMonitor.java

private static String getStackTrace(Thread t) {
    StackTraceElement[] eList = t.getStackTrace();
    StringBuilder trace = new StringBuilder();
    for (StackTraceElement e : eList) {
        trace.append("\n\tat ");
        trace.append(e.getClassName() + "." + e.getMethodName() + "(" + e.getFileName() + ":"
                + e.getLineNumber() + ")");
    }//from  w w  w  . ja  v  a  2  s . c om
    return trace.toString();
}

From source file:Main.java

private static String generateVerboseTag(StackTraceElement caller) {
    String tag = "%s.%s(L:%d)";
    String callerClazzName = caller.getClassName();
    callerClazzName = callerClazzName.substring(callerClazzName.lastIndexOf(".") + 1);
    tag = String.format(tag, callerClazzName, caller.getMethodName(), caller.getLineNumber());
    tag = TextUtils.isEmpty(customTagPrefix) ? tag : customTagPrefix + ":" + tag;
    return tag;/*  w w w  .ja v  a 2  s.  c o  m*/
}

From source file:Main.java

private static String generateTag(StackTraceElement caller) {
    String tag = "%s.%s(Line:%d)";
    String callerClazzName = caller.getClassName();
    callerClazzName = callerClazzName.substring(callerClazzName.lastIndexOf(".") + 1);
    tag = String.format(tag, callerClazzName, caller.getMethodName(), caller.getLineNumber());
    tag = TextUtils.isEmpty(customTagPrefix) ? tag : customTagPrefix + ":" + tag;
    return tag;//  w w  w  .  ja  v a  2  s.co m
}

From source file:Main.java

public static void printStackTrace(final StackTraceElement[] stack, StringBuffer b) {
    for (int i = 0; i < stack.length; ++i) {
        StackTraceElement e = stack[i];
        b.append("\t at ");
        b.append(e.getClassName());/*from   w w  w  .  jav  a  2  s  .com*/
        b.append(".");
        b.append(e.getMethodName());
        b.append("(");
        b.append(e.getFileName());
        b.append(":");
        b.append(e.getLineNumber());
        b.append(")\n");

    }
    //b.append("\n");
}

From source file:Main.java

public static String getThreadStack(Thread t) {
    StackTraceElement[] stacks = t.getStackTrace();
    StringBuffer buffer = new StringBuffer();
    for (StackTraceElement stack : stacks) {
        String filename = stack.getFileName();
        if (filename == null) {
            filename = "NULL";
        }/*from  w w w.  jav a2 s  . co  m*/
        String className = stack.getClassName();
        String methodName = stack.getMethodName();
        int line = stack.getLineNumber();
        buffer.append(String.format("%s.%s(%s:%d)\r", className, methodName, filename, line));
    }
    return buffer.toString();
}

From source file:org.apache.tajo.exception.ExceptionUtil.java

/**
 * Return the string about the exception line ; e.g.,)
 * <code>Line 195 in JdbcTablespace.java</code>
 *
 * @return A string representing the line number and source file name at which the exception occurs.
 *//*from   w  ww  .  ja v  a 2 s.  co  m*/
@SuppressWarnings("unused")
public static String getExceptionLine() {
    StackTraceElement stack = Thread.currentThread().getStackTrace()[3];
    return "Line " + stack.getLineNumber() + " in " + stack.getFileName();
}

From source file:org.openmrs.module.hl7query.util.ExceptionUtil.java

/**
 * Wraps the exception message as a SimpleObject to be sent to client
 * //from  w  w  w. j  a  v a 2 s  .com
 * @param ex
 * @param reason
 * @return
 */
public static AuthenticationErrorObject wrapErrorResponse(Exception ex, String reason) {
    LinkedHashMap map = new LinkedHashMap();
    if (reason != null && !reason.isEmpty()) {
        map.put("message", reason);
    } else
        map.put("message", ex.getMessage());
    StackTraceElement ste = ex.getStackTrace()[0];
    map.put("code", ste.getClassName() + ":" + ste.getLineNumber());
    map.put("detail", ExceptionUtils.getStackTrace(ex));
    return new AuthenticationErrorObject().add("error", map);
}

From source file:Main.java

private static String generateTag() {
    StackTraceElement caller = new Throwable().getStackTrace()[2];
    String tag = "%s.%s(L:%d)";
    String callerClazzName = caller.getClassName();
    callerClazzName = callerClazzName.substring(callerClazzName.lastIndexOf(".") + 1);
    tag = String.format(tag, callerClazzName, caller.getMethodName(), caller.getLineNumber());
    tag = TextUtils.isEmpty(customTagPrefix) ? tag : customTagPrefix + ":" + tag;
    return tag;//from   w  w  w  .j av  a2 s  .  c  om
}