您是第 Web Page Tracking 位访客

水~墨~

昂首阔步,不留一点遗憾!

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

 

异常主要有 应用程序异常和公共语言库异常。

比如: DirectoryNotFoundException  不存在文件夹

        FileNotFoundException  文件没找到异常

       InvalidCastException 类型错误异常

 

通用结构

try{}

catch(Exception e){}

finally{}

 

注意:

1.finally 中的代码是必执行的,即使 catch 代码段中有 return字样。

2. 多个catch,只会捕捉最上面的异常,只要捕捉到一个异常,后面的异常就不会捕捉了。所以最上面应该为最具体的异常。

3. 当多个try 嵌套后, 里面捕捉的异常后,外面的异常不会捕捉到。

 

 

代码抛出异常

throw  new FileNotFoundException(“文件没找到”);

 

自定义异常累  customizeException     定义3个构造函数即可。

 

class customize1Exception:Exception
{
public customize1Exception()
{

}
public customize1Exception(string message)
:base(message)
{

}
public customize1Exception(string message, Exception inner)
: base(message, inner)
{

}
}

 

 

 

 

抛出自定义异常throw new customizeException(“文件没找到”);

posted on 2013-04-09 17:43  水墨.MR.H  阅读(206)  评论(0编辑  收藏  举报
知识共享许可协议
本博客为水墨原创,基于Creative Commons Attribution 2.5 China Mainland License发布,欢迎转载,演绎或用于商业目的,但是必须保留本文的水墨(包含链接)。如您有任何疑问或者授权方面的协商,请给我留言。