X hits on this document

1043 views

0 shares

0 downloads

0 comments

313 / 396

C# LANGUAGE SPECIFICATION

Once a matching catch clause is found, the system prepares to transfer control to the first statement of the catch clause. Before execution of the catch clause begins, the system first executes, in order, any finally clauses that were associated with try statements more nested that than the one that caught the exception.

If no matching catch clause is found, one of two things occurs:

If the search for a matching catch clause reaches a static constructor (§‎10.11) or static field initializer, then a System.TypeInitializationException is thrown at the point that triggered the invocation of the static constructor. The inner exception of the System.TypeInitializationException contains the exception that was originally thrown.

If the search for matching catch clauses reaches the code that initially started the thread, then execution of the thread is terminated. The impact of such termination is implementation-defined.

Exceptions that occur during destructor execution are worth special mention. If an exception occurs during destructor execution, and that exception is not caught, then the execution of that destructor is terminated and the destructor of the base class (if any) is called. If there is no base class (as in the case of the object type) or if there is no base class destructor, then the exception is discarded.

16.4 Common Exception Classes

The following exceptions are thrown by certain C# operations.

System.ArithmeticException

A base class for exceptions that occur during arithmetic operations, such as System.DivideByZeroException and System.OverflowException.

System.ArrayTypeMismatchException

Thrown when a store into an array fails because the actual type of the stored element is incompatible with the actual type of the array.

System.DivideByZeroException

Thrown when an attempt to divide an integral value by zero occurs.

System.IndexOutOfRangeException

Thrown when an attempt to index an array via an index that is less than zero or outside the bounds of the array.

System.InvalidCastException

Thrown when an explicit conversion from a base type or interface to a derived type fails at run time.

System.NullReferenceException

Thrown when a null reference is used in a way that causes the referenced object to be required.

System.OutOfMemoryException

Thrown when an attempt to allocate memory (via new) fails.

System.OverflowException

Thrown when an arithmetic operation in a checked context overflows.

System.StackOverflowException

Thrown when the execution stack is exhausted by having too many pending method calls; typically indicative of very deep or unbounded recursion.

System.TypeInitializationException

Thrown when a static constructor throws an exception, and no catch clauses exists to catch it.

300Copyright Microsoft Corporation 1999-2003. All Rights Reserved.

Document info
Document views1043
Page views1043
Page last viewedSat Dec 10 10:18:22 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments