13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>C#</strong> LANGUAGE SPECIFICATIONthe run-time type of the exception being thrown. A catch clause that doesn’t name an exception class canhandle any exception.Once a matching catch clause is found, the system prepares to transfer control to the first statement of thecatch clause. Before execution of the catch clause begins, the system first executes, in order anyfinally clauses that were associated with try statements more nested that than the one that caught theexception.If no matching catch clause is found, one of two things occurs:• If the search for a matching catch clause reaches a static constructor (§17.11) or static field initializer,then a System.TypeInitializationException is thrown at the point that triggered the invocationof the static constructor. The inner exception of the System.TypeInitializationExceptioncontains the exception that was originally thrown.• If the search for matching catch clauses reaches the code that initially started the thread, then executionof 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 duringdestructor execution, and that exception is not caught, then the execution of that destructor is terminated andthe 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.23.4 Common Exception ClassesThe following exceptions are thrown by certain <strong>C#</strong> operations.System.ArithmeticExceptionSystem.ArrayTypeMismatchExceptionSystem.DivideByZeroExceptionSystem.IndexOutOfRangeExceptionSystem.InvalidCastExceptionSystem.NullReferenceExceptionSystem.OutOfMemoryExceptionSystem.OverflowExceptionSystem.StackOverflowExceptionSystem.TypeInitializationExceptionA base class for exceptions that occur duringarithmetic operations, such asSystem.DivideByZeroException andSystem.OverflowException.Thrown when a store into an array fails because theactual type of the stored element is incompatiblewith the actual type of the array.Thrown when an attempt to divide an integralvalue by zero occurs.Thrown when an attempt to index an array via anindex that is less than zero or outside the bounds ofthe array.Thrown when an explicit conversion from a basetype or interface to a derived type fails at run time.Thrown when a null reference is used in a waythat causes the referenced object to be required.Thrown when an attempt to allocate memory (vianew) fails.Thrown when an arithmetic operation in achecked context overflows.Thrown when the execution stack is exhausted byhaving too many pending method calls; typicallyindicative of very deep or unbounded recursion.Thrown when a static constructor throws anexception, and no catch clauses exists to catch it.304

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!