.NET Framework picks (5) abnormal

xiaoxiao2021-03-06  87

.NET Framework picks (5) abnormal

1. Overview Programs must be able to unify errors that occur during execution

Traditionally, the error handling model depends on language detection errors and the unique way to find errors or depends on the error handling mechanism provided by the operating system.

The exception handling of the running library has the following features: Do not require any specific language syntax when considering the language or the language exception processing of the abnormality is derived, but allow each language to define its own syntax allows cross-process or even cross Computer boundary triggered abnormalities

An exception is from an Exception class inherited object abnormality from a problem code area, and then passs upward along the stack, it is really until the application handles the running library to create an exception information table for each executable. The method has an associated exception handling information array array to describe a protected code block, any exception filter associated with the code (Catch statement)

The 2.Exception class represents an error that occurs during execution of the application. The signature is as follows: System.Object System.Exception derived class Public Class Exception Implements iSerializable

If the application will process an exception that occurs during the execution of the application code block, the code must be placed in the TRY statement. Each CatCH block includes a type filter that determines an exception type of the block.

When an exception occurs in the TRY block, the system searches them in the order in which the CATCH block appears in the application code until it is positioned to the CATCH block processed. If a CATCH block type filter specifies the type of T or any faction of T, the CAT block processes the T type exception. The system stops searching after finding the first CATCH block that handles the exception. Processing a type of Catch block in the application code must be specified before the Catch block processing its base type. Handle the Catch block of System.Exception finally specified.

If all CATCH blocks associated with the current TRY block do not process the exception, and the current TRY block is nestled in the other TRY block currently called, the CATCH block associated with the next closed try block is searched. If you do not find the Catch block for this exception, the system searches for the nesting level in the current call. If the CATCH block for this exception is not found in the current call, the exception edge tuning stack is passed upward, and the last stack frame is searched to find the Catch block that handles the exception. Continue to search the calling stack until the exception is processed or called no more frames in the stack. If the Catch block that is not found in the top of the calling stack, the exception is processed by the default exception handler, and then the application terminates.

There are two types of exceptions under the base class Exception: the predefined public language running library exception class is derived from SystemException. User-defined application exception class defined from ApplicationException.

The properties of the Exception class StackTrace Properties: Public Overridable Readonly Property StackTrace AS String can be used to determine the stack tracking of the error occurs. If there is available debugging information, the stack trace contains the source file name and the program line number.

Innerexception Properties: Public Readonly Property Innerexception As Exception is used to create and retain a series of exceptions during exception processing. You can use this property to create a new exception to include the previous captured exception. Original exception can be captured by the second exception in the Innerexception property, which allows the second exception to check the additional information. For example, suppose there is a method of reading a file and formatting the corresponding data. The code is trying to read from the file, but triggered FileException. This method captures FileException and triggers BadFormATexception. In this case, FileException can be saved in the Innerexception property of the BadFormATexception. Message Properties: Public Overridable Readonly Property Message As String provides detailed information about exception causes. Message is represented by the language specified by the thread.currentuicultuiculture property specified by the thread of the abnormal thread.

Helplink Property: Public Overridable Property Helplink AS String This property saves a URL (or URN) of a helper file that provides a lot of information about exception causes.

Most of the classes inherited from Exception do not implement other members or provide additional features; they are only inherited from Exception. Therefore, the most important information about the abnormality can be found in an exception hierarchy, an abnormality name, and an exception.

EXP

'********************************************************** *********************************************************** ****** Imports SystemClass ExceptionTestClass Public Shared Sub Main () Dim x As Integer = 0 Try Dim y As Integer = 100 / x Catch e As ArithmeticException Console.WriteLine ( "ArithmeticException Handler: {0}", e.ToString ()) Catch e as Exception console.writeline ("Generic Exception Handler: {0}", E.TOSTRING ()) End Try End Sub 'MAINEND CLAS' EXCETIONTESTCLASS '************* *********************************************************** ************************************************

3. The abnormal hierarchy has two types of exceptions: an exception generated by the exception generated by the execution program generated. In addition, there is a hierarchy that caused by the application or running library.

Exception is an abnormal base class. Several exception classes are inherited directly from Exception, including ApplicationException and SystemException. These two classes constitute the basis for almost all running abnormalities.

Most of the exception derived from Exception does not add any features to the Exception class. For example, the INVALIDCASTEXCEPTION class hierarchy is as follows: Object Exception SystemException InvalidCastException error occurs, the runtime is initiated by the SysteMexception. These errors are caused by failed runtime checks (such as array beyond boundary errors), which can occur during the execution of any method. ApplicationException is triggered by the user program instead of running. If you design a new exception application, those exceptions should be derived from the ApplicationException class.

It is not recommended to capture systemException, which triggers SystemException in the application is not a good programming approach.

The most serious abnormality, that is, the exceptions triggered by the runtime or in the unrecoverable case, including ExecutionEngineException, StackoverFlowException, and OutofMemoryException.

The interactive operation is derived from SystemException and is further extended by ExternalException. For example, COMEXCEPTION is an exception thrown during the COM Interop operation, which is derived from ExternalException. Win32Exception and Sehexception are also derived from ExternalException.

The run library anomaly hierarchy runs has a group of foundations derived from SystemException, which triggers these exceptions when performing each directive.

Anomaly Type Class Type Description Example ExceptionObject All exception class. None (using this unusual derived class).

SYSTEMEXCEPTION

Exception is the wrong base class generated by all runtime. None (using this unusual derived class).

IndexOutofRangeException

The systemException is only caused by the runtime when indexing the array. An index of an array of valid ranges in array: Arr [arr.length 1]

NullReferenceException

SystemException is only caused by the runtime when referenced by an empty object. Object o = null; o.tostring ();

INVALIDOPERATIONEXCEPTION

SystemException When in an invalid state, the method is triggered. Remove ENUMERATOR.getNext () from the base collection.

Argumentexception

SystemException base class for all parameter exceptions. None (using this unusual derived class).

Argumentnullexception

ArgumentException is triggered by a method that does not allow parameters. String s = null; "Calculate" .indexof (s);

ArgumentOutofRangeException

ArgumentException is triggered by the verification parameter in a given range. String s = "string"; s.Chars [9];

ExternalException

SystemException occurs in an external environment of the running library or an exception of such environments. None (using this unusual derived class).

Comexception

ExternalException is unusual to encapsulate Com HRESULT information. Use in COM Interop. Sehexception

ExternalException package Win32 has an abnormality of information structure. Used in the unmanaged code intero.

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

New Post(0)