【问题标题】:if specific exception is caught return to code below the line where it was thrown如果捕获到特定异常,则返回到引发异常的行下方的代码
【发布时间】:2021-07-13 23:10:12
【问题描述】:

这可能很愚蠢,但是,是否有可能捕获特定异常,然后返回到函数中稍后抛出异常的位置?

例如

Try
{
//trigger exception 
//return to function here
//more function
}
catch(Exception e)
{
if (e.Message.Contains("exception message contents"))
{Do the return thing}
}

【问题讨论】:

  • 简短的回答是否定的。您能否向我们展示一个更有意义的代码示例,以便我们提供一些建议?并解释你为什么要这样做?
  • 你可以查看这个答案:Resumable exception c#

标签: c# exception try-catch


【解决方案1】:

没有什么能阻止你在尝试中尝试..

try{
    //some code

    try{ couldGoBoom(); } catch (SomeException) { ... }

    //code you want to "return to"'after the SomeException is done with
} catch(OtherException){
    //etc
}

【讨论】:

  • 效果很好,非常感谢!
猜你喜欢
  • 2014-05-16
  • 1970-01-01
  • 2016-07-09
  • 1970-01-01
  • 1970-01-01
  • 2011-07-19
  • 2017-03-22
  • 1970-01-01
相关资源
最近更新 更多