Exception Handling Statements (C# Reference)
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)的更多相关文章
- C#编程.异常处理(Exception Handling Statements)
C#语言包含结构化异常处理(Structured Exception Handling,SEH). throw The throw statement is used to signal the oc ...
- How a C++ compiler implements exception handling
Introduction One of the revolutionary features of C++ over traditional languages is its support for ...
- Structured Exception Handling
https://docs.microsoft.com/en-us/windows/desktop/Debug/structured-exception-handling An exception is ...
- Python - 5.Exception Handling
From:http://interactivepython.org/courselib/static/pythonds/Introduction/ExceptionHandling.html Exce ...
- 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 ...
- Exception Handling引入MVP
异常处理(Exception Handling)是所有系统的最基本的基础操作之一,其它的比如日志(Logging).审核(Auditing).缓存(Caching).事务处理(Transaction) ...
- Unity、Exception Handling引入MVP
什么是MVP?在“MVP初探”里就有讲过了,就是一种UI的架构模式. 简单的描述一下Unity和Exception Handling Application Block: Unity是一个轻量级的可扩 ...
- Exception Handling in ASP.NET Web API webapi异常处理
原文:http://www.asp.net/web-api/overview/error-handling/exception-handling This article describes erro ...
- CoreCLR on Mac:体验managed exception handling
C#测试代码: using System; class Program { static void A() { try { Console.WriteLine("Throwing an ex ...
随机推荐
- ASP.NET CompareValidator 控件在VS2012中出错的问题
CompareValidator 控件用于将由用户输入到输入控件的值与输入到其他输入控件的值或常数值进行比较. -------如果输入控件为空,则不会调用任何验证函数,并且验证将成功.使用 Requi ...
- virtualbox安装ubuntu出现“The system is running in low-graphics mode”
cd /etc/X11 sudo mv xorg.conf.failsafe xorg.conf sudo reboot 即可.
- (二)Android 基本控件
第一节:View 视图组件 Andorid 中的View 视图组件,实现类是android.view.View 类,是绝大多数图形显示类的父类,提供了大量的方法和属性.在View 类下,有很多子类,如 ...
- Objective-c单例模式详解
转载自:http://www.jianshu.com/p/85618bcd4fee 单例模式出现以后,关于它的争执就一直存在.在开发项目中,有很多时候我们需要一个全局的对象,而且要保证全局有且仅有一份 ...
- HttpClient4.3 使用经验(一) 简单使用
package com.wp.nevel.base.utils; import java.io.BufferedOutputStream; import java.io.BufferedReader; ...
- cakephp recursive -1,0,1,2 速查
-1 : model本身 0 :model本身 + belongTo + hasOne 1 :model本身 + belongTo + hasOne + hasMany 2: :model ...
- write() ,read();
int main1(int argc ,char *argv[]){ if(argc < 2 ) return 0; int fd = open(argv[1] , O_RDONLY); if( ...
- PHP类中的__get()和__set函数到底有什么用?
当试图获取一个不可达变量时,类会自动调用__get. 同样的,当试图设置一个不可达变量时,类会自动调用__set. 在网站中,这两个并不是什么非用不可的函数. 例如: Class Test { ...
- AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
http://quote.eastmoney.com/center/list.html#28003501_0_2 http://bbs.tianya.cn/post-53726-21098-1.sht ...
- markdown与textile之间互相转换
markdown与textile之间互相转换 redmine中默认使用的是textile那么从别的地方复制过来的markdown格式的内容需要进行转换 找到一款工具叫做pandoc http://jo ...