C# --try catch finally
来源:互联网 发布:网络搭建移动网络 编辑:程序博客网 时间:2024/05/17 22:14
catch 和 finally 一起使用的常见方式是:在 try 块中获取并使用资源,在catch 块中处理异常情况,并在finally 块中释放资源。
finally 块用于清除 try 块中分配的任何资源,以及运行任何即使在发生异常时也必须执行的代码。控制总是传递给 finally 块,与 try 块的退出方式无关。
复制
// try_catch_finally.csusing System;public class EHClass{ static void Main() { try { Console.WriteLine("Executing the try statement."); throw new NullReferenceException(); } catch (NullReferenceException e) { Console.WriteLine("{0} Caught exception #1.", e); } catch { Console.WriteLine("Caught exception #2."); } finally { Console.WriteLine("Executing finally block."); } }}
示例输出
Executing the try statement.System.NullReferenceException: Object reference not set to an instance of an object. at EHClass.Main() Caught exception #1.Executing finally block.
- C# try catch finally
- C# try, catch ,finally
- C# --try catch finally
- C# try catch finally
- C# try catch finally
- C# try、catch、finally
- C# 捕获异常try...catch...finally
- C#中的try catch 和finally
- try-catch-finally(C# 参考)
- C#中try catch finally 用法
- C#中的try catch finally用法分析
- C#中try catch finally 用法
- C#中的try catch 和finally
- C#中的异常捕获(try catch finally)
- C#中try catch finally 用法
- C#中try catch finally 用法
- try..catch..finally
- try-catch-finally
- AS3中显示对象层级的控制
- struts2中的if/else,iterator标签以及ognl简单使用
- 关于SQL唯一性约束
- Web Service 与 EJB 的分布式的区别
- as3中删除对象的方法
- C# --try catch finally
- 从uboot中学习C语言基本功(uboot/lib_generic/vsprintf.c/simple_strtoul)
- PreparedStatement execute执行插入成功却返回false
- Struts2中的OGNL详解
- C 语言的一些经典题目
- H323与SIP协议对比
- oracle 存储过程基本语法
- 关于几个概念的区分:终端,控制台,shell
- 0x00310030指令引用的0x00310030内存。该内存不能为written