通常我会这样做:
try
{
code
code that might throw an anticipated exception you want to handle
code
code that might throw an anticipated exception you want to handle
code
}
catch
{
}
这种方式有什么好处吗?
code
try
{
code that might throw an anticipated exception you want to handle
}
catch
{
}
code
try
{
code that might throw an anticipated exception you want to handle
}
catch
{
}
code
更新:
我最初在与C#有关的情况下提出了这个问题,但正如A.Levy所评论的那样,它可以适用于任何异常处理语言,因此我更改了标签以反映这一点。