C # Exception Handling

Source: Internet
Author: User
C # Exception Handling

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

2 , error handling in C # Exception management keywords commands have four commands: try , catch, throw, finally , there are four keywords written exception The processing function 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 any type of exception error . You do not need to declare it, in this way, 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: Catch is used to catch exception errors generated in try-catch. You can create Multiple catch blocks to capture different types of exception errors.

3 , C # common exception classes:

class

description

outofmemoryexception

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

stackoverflowexception

when the execution program is advantageous for using Stack resources (usually executing recursion or too many loops ), 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: 12pt; Background: Aqua; color: Blue "> operation failed , this includes dividebyzeroexception and overflowexception

dividebyzeroexception

when division is used, when 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.