//获取行号
public static int getLineNumber(Exception e){
StackTraceElement[] trace =e.getStackTrace();
if(trace==null||trace.length==0) return -1; //
return trace[0].getLineNumber();
}
//获取函数名
public static String fun(Exception e) {
StackTraceElement[] trace = e.getStackTrace();
if (trace == null)
return "";
return trace[0].getMethodName()+"()";
public static int getLineNumber(Exception e){
StackTraceElement[] trace =e.getStackTrace();
if(trace==null||trace.length==0) return -1; //
return trace[0].getLineNumber();
}
//获取函数名
public static String fun(Exception e) {
StackTraceElement[] trace = e.getStackTrace();
if (trace == null)
return "";
return trace[0].getMethodName()+"()";
}
测试:
Log.d("test","function:: " + fun(new Exception())+ " line = "+getLineNumber(new Exception()));
转自:http://blog.csdn.net/u010164190/article/details/53926646