C#处理特定的异常类型
示例
try
{
/* code to open a file */
}
catch (System.IO.FileNotFoundException)
{
/* code to handle the file being not found */
}
catch (System.IO.UnauthorizedAccessException)
{
/* code to handle not being allowed access to the file */
}
catch (System.IO.IOException)
{
/* code to handle IOException or it's descendant other than the previous two */
}
catch (System.Exception)
{
/* code to handle other errors */
}请注意,按顺序评估异常并应用继承。因此,您需要从最具体的内容开始,并以其祖先结尾。在任何给定点,将仅执行一个catch块。
热门推荐
10 送给同桌的祝福语简短
11 新年恋人祝福语简短创意
12 团体年会祝福语简短霸气
13 2026年祝福语大全简短
14 生日祝福语简短搞笑女儿
15 拜新年的祝福语简短
16 要过年了祝福语简短
17 简短佛教新年祝福语大全
18 同事们生日祝福语简短