Exception Handling Statements (C# Reference)

C# provides built-in support for handling anomalous situations, known as exceptions, which may occur during the execution of your program. These exceptions are handled by code that is outside the normal flow of control.

The following exception handling topics are explained in this section:

try-catch-finally (C# Reference)

A common usage of catch and finally together is to

obtain and use resources in a try block,

deal with exceptional circumstances in a catch block,

and release the resources in the finally block.

For more information and examples on re-throwing exceptions, see try-catch and Throwing Exceptions.

For more information about the finallyblock, see try-finally.

public class EHClass
{
void ReadFile(int index)
{
// To run this code, substitute a valid path from your local machine
string path = @"c:\users\public\test.txt";
System.IO.StreamReader file = new System.IO.StreamReader(path);
char[] buffer = new char[];
try
{
file.ReadBlock(buffer, index, buffer.Length);
}
catch (System.IO.IOException e)
{
Console.WriteLine("Error reading from {0}. Message = {1}", path, e.Message);
} finally
{
if (file != null)
{
file.Close();
}
}
// Do something with buffer...
} }

Exception Handling Statements (C# Reference)的更多相关文章

  1. C#编程.异常处理(Exception Handling Statements)

    C#语言包含结构化异常处理(Structured Exception Handling,SEH). throw The throw statement is used to signal the oc ...

  2. How a C++ compiler implements exception handling

    Introduction One of the revolutionary features of C++ over traditional languages is its support for ...

  3. Structured Exception Handling

    https://docs.microsoft.com/en-us/windows/desktop/Debug/structured-exception-handling An exception is ...

  4. Python - 5.Exception Handling

    From:http://interactivepython.org/courselib/static/pythonds/Introduction/ExceptionHandling.html Exce ...

  5. C++ Knowledge series Inheritance & RTTI & Exception Handling

    Inheritance The pointer or reference to base class can address/be assigned with any of the classes d ...

  6. Exception Handling引入MVP

    异常处理(Exception Handling)是所有系统的最基本的基础操作之一,其它的比如日志(Logging).审核(Auditing).缓存(Caching).事务处理(Transaction) ...

  7. Unity、Exception Handling引入MVP

    什么是MVP?在“MVP初探”里就有讲过了,就是一种UI的架构模式. 简单的描述一下Unity和Exception Handling Application Block: Unity是一个轻量级的可扩 ...

  8. Exception Handling in ASP.NET Web API webapi异常处理

    原文:http://www.asp.net/web-api/overview/error-handling/exception-handling This article describes erro ...

  9. CoreCLR on Mac:体验managed exception handling

    C#测试代码: using System; class Program { static void A() { try { Console.WriteLine("Throwing an ex ...

随机推荐

  1. 学习笔记_Java_day12_设计模式MVC(13).JavaWeb的三层框架(14)

    MVC 1. 什么是MVC MVC模式(Model-View-Controller)是软件工程中的一种软件架构模式,把软件系统分为三个基本部分:模型(Model).视图(View)和控制器(Contr ...

  2. ios paper for facebook 使用第三方库

    facebook paper使用的第三方库 Facebook Paper使用的第三方库 第三方库名 简介 链接 ACE code editor https://github.com/ajaxorg/a ...

  3. Java——有关日期的方法

    1.日期转换成String格式化输出: public String getDate() { SimpleDateFormat format = new SimpleDateFormat("y ...

  4. windows下ipython的tab补全,只需安装pyreadline即可.

    运行ipython提示缺失模块 在windows下安装readline失败. 根据提示访问 https://urllib3.readthedocs.org/en/latest/security.htm ...

  5. bzoj1688: [Usaco2005 Open]Disease Manangement 疾病管理

    思路:状压dp,枚举疾病的集合,然后判断一下可行性即可. #include<bits/stdc++.h> using namespace std; #define maxs 400000 ...

  6. 九度OJ 1371 最小的K个数 -- 堆排序

    题目地址:http://ac.jobdu.com/problem.php?pid=1371 题目描述: 输入n个整数,找出其中最小的K个数.例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4 ...

  7. ORACLE数据库闪回日志写满

    网站页面无法显示完整.检查web服务是正常的,所以可能是ORACLE数据库出了问题. 首先检查闪回日志写满 然后检查归档日志文件写满的缘故了.使用以下几个命令可以看出当前归档日志文件的使用情况: se ...

  8. linux驱动(一)

    编写模块必须先声明下面两句: #include <linux/module.h>               //这个头文件包含了许多符号与函数的定义,这些符号与函数多与加载模块有关 #i ...

  9. 《JavaScript高级程序设计》笔记(2):位操作符

    1.按位非(NOT) 2.按位与(AND) 3.按位或(OR) 4.按位异或(XOR) 5.左移 6.有符号右移 7.无符号右移 ----------------------------------- ...

  10. (转载).Net HttpPost的发送和接收示例代码

    HttpPost在不同系统进行数据交互的时候经常被使用.它的最大好处在于直接,不像Webservice或者WCF需要wsdl作为一个双方的"中介".在安全性上,往往通过IP限制的方 ...