[New] Use StackWalker instead of new Throwable().getStackTrace()[depth]
This commit is contained in:
parent
37e239e3de
commit
75ca814ba0
|
@ -39,13 +39,9 @@ public class ExceptionHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getCallerMethod(int depth) {
|
public static String getCallerMethod(int depth) {
|
||||||
// TODO change to StackWalker:
|
return StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE) //
|
||||||
// StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
|
.walk(frames -> frames.map((StackWalker.StackFrame sf) -> sf.getClassName() + "." + sf.getMethodName())
|
||||||
// walker.walk(frames -> frames.skip(1)
|
.skip(depth).findFirst()).orElse("UnknownClass.unknownMethod!");
|
||||||
// .map((StackWalker.StackFrame s) -> s.getDeclaringClass() + "." + s.getMethodName()).findFirst());
|
|
||||||
|
|
||||||
StackTraceElement element = new Throwable().getStackTrace()[depth];
|
|
||||||
return element.getClassName() + "." + element.getMethodName();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue