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 3岁孩子祝福语简短
14 中考祝福语简短卡片大全
15 对生活祝福语简短精辟
16 Q穷人结婚祝福语简短
17 简短朋友旅行祝福语大全
18 18岁祝福语搞笑简短