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反射
原文:http://www.cnblogs.com/zizo/p/3509895.html 两个现实中的例子:1.B超:大家体检的时候大概都做过B超吧,B超可以透过肚皮探测到你内脏的生理情况.这是如何 ...
- python的交代一
把自己one note上面的摘抄和自己的节选,全部粘贴到博客了,时间宝贵,要得太多,技术栈要慢慢发展,python先放放了,也不知道什么时候正式捡起来. 先把目前养活自己的android.java.c ...
- c#调用c++ dll(一)
首先来说说c++中的dll 核心的一些知识 比较大的应用程序都由很多模块组成,这些模块分别完成相对独立的功能,它们彼此协作来完成整个软件系统的工作.可能存在一些模块的功能较为通用,在构造其它软件系统时 ...
- Hyper-V Windows 8.1 & Windows Server 2012 R2 Q&A
从Windows8开始,x64位系统自带Hyper-V功能,很多开发者和专业用户往往希望利用的Microsoft提供的这一免费功能,但是微软在这方面并不是最佳. 主要写几个大家经常遇到的问题. Win ...
- ios PullToRefresh using animated GIF or image array or Vector image
说说那些令人惊叹的下拉效果 1. 动画下拉,这里借用一下github的资源 优点:直接用gif图处理,下拉进度完全按照gif图运行时间,只要时间和下拉进度匹配就可以了, 效果很流畅 https://d ...
- ARC和MRC实现单例模式
代码如下,可直接拷贝到头文件中 #define singleton_h(name) +(instancetype)shared##name # if __has_feature(objc_arc) / ...
- 写漂亮C#代码的小技巧
第一次写博客,不知道代码用什么编辑,直接截图了,哈哈哈.... 我自己不喜欢看随便复制粘贴过来一堆代码的博客,所以,用些简单点的例子吧,希望对大家有帮助... ------------------- ...
- Druid 简单介绍
官方网址:http://code.alibabatech.com/wiki/display/Druid/Home 1.什么是Druid Druid首先是一个数据库连接池.Druid是目前最好的数据库连 ...
- 这样写JS的方式对吗?
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Core模块其他常用知识点[OpenCV 笔记14]
Matx 轻量级的Mat,必须在使用前规定好大小,比如一个2x3的float型的Matx,可以声明为Matx23f Vec Vec是Matx的一个派生类,是一个一维的Matx,跟vector很相似.在 ...