如何抛出异常而不重置堆栈跟踪? [英] How to throw exception without resetting stack trace?

查看:118
本文介绍了如何抛出异常而不重置堆栈跟踪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是有一个后续问题throw和throw ex之间的区别

有没有办法提取新的错误处理方法而不重置堆栈跟踪?

is there a way to extract a new error handling method without resetting the stack trace?


我将尝试内部方法和另一个 answer ,看哪一个可以更好地标记一个答案。

I will be trying both "inner method" and another answer provided by Earwicker and see which one can work out better to mark an answer.

推荐答案

不知道如果你的意思是,但我的建议在你的另一个问题是解决这个问题。

Not sure if you mean that, but my suggestion in your other question was addressing this.

如果你的处理程序返回一个布尔值,无论是否处理了异常,你可以在你的catch子句中使用这个:

If your handler returns a boolean whether the exception was handled or not, you can use this in your catch clause:

catch (Exception ex) {
  if (!HandleException(ex)) {
    throw;
  }
}

这篇关于如何抛出异常而不重置堆栈跟踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆