开发者

Stack call in Exception Handling

开发者 https://www.devze.com 2022-12-08 07:52 出处:网络
According to the design guideline the catching exception should start from more specification exception to System.Exception.

According to the design guideline the catching exception should start from more specification exception to System.Exception.

like :

try
{


}
catch(IOException IOEx)
{
}
catch(ArrayIndexOutOfRangeException AIE)
{
}
.....
catch(Exception ex)
{
}

I he开发者_如何学Card that CLR tracks the stack to trace the exception one by one to find the matching one(if an error occur). As stack is "Last in first out" in nature won't CLR look in reverse order ? ( i.e Exception .. ArrayIndexOutOfRangeException .. IOException)


No - the stack in this case is the call stack, so if it doesn't find a handler in the current method, it will move up the stack to look for a handler. Within a particular method however, handlers are tested in the order they are specified.

0

精彩评论

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