相关疑难解决方法(0)

嵌套的Try/Catch阻止了一个坏主意吗?

假设我们有这样的结构:

Try
  ' Outer try code, that can fail with more generic conditions, 
  ' that I know less about and might not be able to handle

  Try
    ' Inner try code, that can fail with more specific conditions,
    ' that I probably know more about, and are likely to handle appropriately
  Catch innerEx as Exception
    ' Handle the inner exception
  End Try

Catch outerEx as Exception
  ' Handle outer exception
End Try
Run Code Online (Sandbox Code Playgroud)

我已经看到一些意见认为这样的嵌套Try块是不鼓励的,但我找不到任何具体的原因.

这是坏代码吗?如果是这样,为什么?

.net vb.net exception-handling

77
推荐指数
2
解决办法
7万
查看次数

标签 统计

.net ×1

exception-handling ×1

vb.net ×1