Throwable (@NotNull Throwable th, @NotNull Throwable relativeTo) { StackTraceElement[] trace = th.getStackTrace(); StackTraceElement[] rootTrace = relativeTo.getStackTrace(); for (int i = 0, len = Math.min(trace.length, rootTrace.length); i < len; i++) { if (trace[trace.length - i - 1].equals(rootTrace[rootTrace.length - i - 1])) continue; int newDepth = trace.length - i; th.setStackTrace(Arrays.copyOf(trace, newDepth)); break; } return th; }