throwWithStackTrace 静态方法
- @Since("2.16")
- Object error,
- StackTrace stackTrace
将带有相关堆栈跟踪 stackTrace 的 error 抛出。
其行为类似于在抛出时,如果 StackTrace.current 是 stackTrace,则 throw error 将会表现。
类似于 throw,如果 error 继承自 Error 且尚未被抛出,它的 Error.stackTrace 属性将被设置为 stackTrace。
这个函数不能保证保留 stackTrace 的身份。在通过 try/catch 捕获的由这个错误生成的 StackTrace 对象,或者设置为一个 error 的 Error.stackTrace 的对象可能不是提供的作为参数的同一 stackTrace 对象,但其内容将根据 StackTrace.toString 保持相同。
实现
@Since("2.16")
static Never throwWithStackTrace(Object error, StackTrace stackTrace) {
checkNotNullable(error, "error");
checkNotNullable(stackTrace, "stackTrace");
_throw(error, stackTrace);
}