// Log.d("5555555555555", "信息"+Tools.getMyStackTraceInfo(new Exception()));
// Log.d("5555555555555", "信息"+Tools.getStackTraceInfo(new Exception()));
/**
*得到Exception所在代码的行信息
*如果没有行信息,返回null
*/
public static String getMyStackTraceInfo(Exception e){
StackTraceElement[] trace =e.getStackTrace();
if(trace==null||trace.length==0) return null;
return trace[0].getFileName()+trace[0].getClassName()+trace[0].getMethodName()+trace[0].getLineNumber();
}
/**
*得到Exception所在代码的行信息
*如果没有行信息,返回null
*/
public static String getStackTraceInfo(Exception e){
StackTraceElement[] trace =e.getStackTrace();
if(trace==null||trace.length==0) return null;
return trace[0].toString();
}
Android 代码里 用log打印 该行的类名、文件名、方法名、行号等信息
最新推荐文章于 2024-05-17 15:34:11 发布