C # exception handling [reprinted]

Source: Internet
Author: User

1, C # all Exception Handling are consideredClass, All exceptions are causedSystem. ExceptionDerived from.

2Handle errors in C #Exception managementKeywordsThere are four commands:Try, Catch, throw, finallyThe exception handling function compiled with these four keywords is very powerful and convenient.

3 . syntax for exception handling: try { Code }< span style =" Background: lime; color: blue; "> catch ( Exception Handling statement ( declare the catch section to capture which type of exception error , you do not need to declare it, so that the catch will catch any type of exception errors.) { Exception Handling Program Code (when catch after an exception error is caught , the use the corresponding program code )} Note: Use catch to catch exception errors generated in try-catch. You can create multiple catch segments to capture different types of exception errors.

3,C #Common exceptions:

Class

Description

outofmemoryexception

when a memory allocation fails to be initialized using the new keyword

stackoverflowexception

when the execution program is advantageous to the use of stack resources (usually the execution of recursion or too many cycles ), when stack resources are exhausted

nullreferenceexception

when you want to use the reference object, it is nullreference

typeinitializationexception

if an error occurs to a static object, but the catch section is missing for processing and response time

arraytypemismatchexception

when the stored data is different from the data type in the array

indexoutofrangeexception

when the range of the array is exceeded

multicastnotsupportedexception

When merging two delegate objects fails

arithmeticexception

generally in operation failed , this includes dividebyzeroexception and overflowexception

dividebyzeroexception

when division is used and the denominator is 0,

overflowexception

when the operation exceeds the valid range of data types

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.