开发者

Is the order of Catch blocks important?

Just making sure I understand it well. Is the correct schema correct? Ca开发者_运维知识库tching the most specific exceptions first to catching broader exceptions with general catch at the end of the set of catch blocks.

try
{
 some code
}


catch(SomeSpecificException ex)
{
}
catch(LessSpecificException ex)
{
}
catch
{
  //some general exception
}


I believe it won't let you write it in the incorrect order.

This generates an error:

try
{
    throw new OutOfMemoryException();
}
catch(Exception ex)
{
    "B".Dump();
}
catch(OutOfMemoryException ex)
{
    "A".Dump();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜