C# exception class related summary

C# exception class one, base class Exception

C# Exception Class Two, Common Exception Class

1. SystemException class: This class is the base class of all other exception classes in the System namespace. (Suggestion: Common language runtime exceptions usually use this type)

2. ApplicationException class: This class represents the exception that is raised when a non-fatal error occurs in the application (recommendation: this is usually used for exceptions caused by the application itself)

C# exception class III. Exception class related to parameters

This type of exception class is derived from SystemException, used to deal with the exception of the parameters passed to the method member

1. ArgumentException class: This class is used to handle exceptions with invalid parameters. In addition to the inherited property name, this class also provides a string type property ParamName representing the name of the parameter that caused the exception.

2. FormatException class: This class is used to handle the exception of parameter format errors.

C# Exception Class IV. Exceptions related to member access

1, MemberAccessException class: This class is used to handle exceptions caused when accessing members of the class fails. The reason for the failure may be that there are insufficient access rights, or the member to be accessed does not exist at all (commonly used when calling between classes)

2. Direct derived class of MemberAccessException class:

i. FileAccessException class: This class is used to handle exceptions caused by failure to access field members

ii. MethodAccessException class: This class is used to handle exceptions caused by failure to access method members

iii. MissingMemberException class: This class is used to handle exceptions that are thrown when the member does not exist

C# Exception Class 5. Exceptions related to arrays

The following three classes are inherited from the SystemException class

1. IndexOutOfException class: This class is used to handle exceptions caused by subscripts exceeding the length of the array

2. ArrayTypeMismatchException class: This class is used to handle exceptions caused by storing elements with incorrect data types in the array

3. RankException class: this class is used to handle exceptions caused by dimensionality errors

C# Exception Class VI. IO-related exceptions

1. IOException class: This class is used to handle exceptions caused by file input and output operations.

2. Five directly derived classes of the IOException class:

i. DirectionNotFoundException class: This class is used to handle exceptions caused by not finding the specified directory.

ii. FileNotFoundException class: This class is used to handle exceptions caused by not finding a file.

iii. EndOfStreamException class: This class is used to deal with exceptions that have reached the end of the stream and continue to read data.

iv. FileLoadException class: This class is used to handle exceptions caused by the inability to load files.

v. PathTooLongException class: This class is used to handle exceptions caused by the file name being too long.

C# exception class seven, exceptions related to arithmetic

1. ArithmeticException class: This class is used to handle exceptions related to arithmetic.

2. Derived class of ArithmeticException class:

i. DivideByZeroException class: represents an exception caused by trying to divide by zero in integer or decimal operations.

ii. NotFiniteNumberException class: indicates the exception caused by infinite dozen or non-negative value in floating-point operations.

 

The exception classes in the .NET framework are derived from the SystemException class. Most of the commonly used members of this class are as follows:

 

HelpLink is a link to a help file that provides information about the exception. 

Message is the text indicating the details of an error. 

Source The name of the object or application that caused the exception. 

StackTrace is a list of methods called in the stack. 

TargetSite is the name of the method that throws the exception.

 

Try/Catch/Finally 块

C# uses Try/Catch/Finally block to handle an exception.

The Try statement indicates that the code block that throws an exception needs to be monitored during execution.

The Catch statement specifies the code block that should be executed after the Try code block is executed. This code block will be executed regardless of whether an exception occurs. In fact, it is often used for cleanup code that may be required.
Original address: http://www.cnblogs.com/PaulMa/archive/2011/06/25/2090177.html 

Guess you like

Origin blog.csdn.net/zhengjian1996/article/details/112917085