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 |