6.3. 编写代码
public bool ProcessWithWrap()
{
try
{
this.ProcessB();
}
catch(Exception ex)
{
// Quick Start is configured so that the Wrap Policy will
// log the exception and then recommend a rethrow.
bool rethrow = ExceptionPolicy.HandleException(ex, "Wrap Policy");
if (rethrow)
{
throw;
}
}
return true;
}
小结
try { //执行的代码,其中可能有异常。一旦发现异常,则立即跳到catch执行。否则不会执行catch里面的内容 }
catch { //除非try里面执行代码发生了异常,否则这里的代码不会执行 }
finally { //不管什么情况都会执行,包括try catch 里面用了return ,可以理解为只要执行了try或者catch,就一定会执行 finally }
注:相关教程知识阅读请移步到c#教程频道。










