C # abnormal processing mechanism (black flash)

xiaoxiao2021-03-06  14

TRY is used to check an exception that occurs and helps send any possible exceptions.

Catch handles errors in a larger way to control, and you can have multiple CATCH clauses.

Finally's code blocks will be executed regardless of whether abnormalities have caused an exception.

Throw is used to trigger an exception, which can trigger predefined exceptions and custom exceptions.

Try

{

Program block;

}

Catch (Exception E)

{

Exception handling code block;

}

Finally

{

The code block to be executed regardless of whether abnormalities occur;

}

The following table gives some common exceptions:

Commonly used in the SYSTEM namespace

Abnormal class name brief description

MEMBERACCESSEXCEPTION access error: Type member cannot be accessed

ArgumentException parameter error: The parameters of the method are invalid

The argumentnullexception parameter is empty: pass an unacceptable empty parameter to the method

Arithmeticexception mathematical calculation error: Due to the abnormality caused by mathematical calculations, the coverage is wide.

ArrayTypeMatchThexception array type does not match

DivideByzeroException is zero

The format of the Formatexception parameter is incorrect

IndexOutofRangeException index is out of range, less than 0 or the index of the last element is large

INVALIDCASTEXCEPTION illegally enforced conversion, triggered during explicit conversion failure

MulticastNotSupportedException is not supported by multicast: combined two non-empty appointments fail

NotSupportedException calls are not implemented in the class

NullReferenceException triggered when references an empty reference object

OutofMemoryException cannot be caused for the new statement to allocate memory, insufficient memory

Overflowexception overflow

StackoverflowException stack overflow

TypeInitializationException Error Initiation Type: Static constructor triggered

NOTFINITENUMBEREXCEPTION 无限 无限 无限: Number is not legal

Define your own anomaly

In addition to predefined abnormalities, we can also create our own exception, the process is relatively simple:

(1) Declare an exception, the format is as follows:

Class ExceptionName: Exception {}

(Ii) Executivity:

Throw (ExceptionName);

转载请注明原文地址:https://www.9cbs.com/read-49403.html

New Post(0)