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. iOS iOS与html进行交互

    实现的 效果就是上边那样:首先通过webview 进行网络请求 然后进行显示. 然后点击下一页的按钮 通过js的响应显示另一个网页 最后通过下一页的按钮可以返回到首页. 本文仅仅是h5跟ios 的交互 ...

  2. C#微信开发之旅--自定义菜单

    上一篇说道基本信息的回复<C#微信开发之旅--基本信息的回复>,当中就说到文本信息的回复,其他信息的回复,可以参考下开发文档中回复信息的格式进行修改就可以. 下面来实现下自定义菜单.据我了 ...

  3. 关于cnpm的一点小bug

    在实际工作中,一个项目完成后,在上线前,常常需要把代码进行压缩,一般是用gulp或者 webpack 进行压缩.(小妹是用gulp) gulp是运行在node 环境下的. 所以首先,下载并安装了nod ...

  4. 10.29_Extjs-lovcombo

    (1) Ext.ux.form.LovCombo多选下拉框 :http://www.iteye.com/topic/340900 (2)combox:icon,lovcombo:icon (3) (4 ...

  5. OpenCV(5)-图像掩码操作(卷积)-锐化

    锐化概念 图像平滑过程是去除噪声的过程.图像的主要能量在低频部分,而噪声主要集中在高频部分.图像的边缘信息主要也在高频部分,在平滑处理后,将会丢不部分边缘信息.因此需要使用锐化技术来增强边缘. 平滑处 ...

  6. 使用宏定义来减少JNI的繁琐

    本篇文章由:http://www.sollyu.com/use-macro-definitions-to-reduce-tedious-jni/ 说明 相信写过cocos2d-x的朋友,或者写过jni ...

  7. spark - 将RDD保存到RMDB(MYSQL)数据库中

    SCALA连接数据库批量插入: scala> import java.sql.DriverManager scala> var url = "jdbc:mysql://local ...

  8. yum --rpm包安装

    rpm -ivh  package -i 表示安装install -v表示显示详细信息, -vv更详细些 -h表示显示安装进度 --force:表示强制安装 --nodeps:忽略依赖关系安装 --r ...

  9. jQuery EasyUI 提示框(Messager)用法

    jQuery EasyUI 提示框(Messager)不仅强大,而且也不用任何的HTML代码,只需要按照<jQuery EasyUI框架使用文档>包含必要文件后,在$(function() ...

  10. H5小内容(五)

    Geolocation(地理定位)   基本内容     地理定位 - 地球的经度和纬度的相交点     实现地理定位的方式       GPS - 美国的,依靠卫星定位       北斗定位 - 纯 ...