ILGenerator.EndExceptionBlock Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Ends an exception block.

Namespace: System.Reflection.Emit
Assembly: mscorlib (in mscorlib.dll)

Syntax

Public Overridable Sub EndExceptionBlock
public virtual void EndExceptionBlock()

Exceptions

Exception Condition
InvalidOperationException

The end exception block occurs in an unexpected place in the code stream.

NotSupportedException

The Microsoft intermediate language (MSIL) that is being generated is not currently in an exception block.

Examples

The following example demonstrates the use of the EndExceptionBlock method to end a try/finally exception block. This code is part of a larger example provided for the BeginExceptionBlock method.

adderIL.BeginFinallyBlock()

' The finally block block displays a message on the TextBlock, if the 
' OutputBlock field has been set. Just as in the catch block, the following
' code tests whether the TextBlock is present, and skips the output if it is
' not present.
adderIL.Emit(OpCodes.Ldsfld, demoOutput)
adderIL.Emit(OpCodes.Ldnull)
adderIL.Emit(OpCodes.Ceq)
adderIL.Emit(OpCodes.Brtrue_S, skipOutputInFinally)

' Append a constant string to the Text property of the TextBlock.
adderIL.Emit(OpCodes.Ldsfld, demoOutput)
adderIL.Emit(OpCodes.Ldsfld, demoOutput)
adderIL.Emit(OpCodes.Callvirt, getter)
adderIL.Emit(OpCodes.Ldstr, "Executing the finally block." & vbLf)
adderIL.Emit(OpCodes.Call, concat2)
adderIL.Emit(OpCodes.Callvirt, setter)

adderIL.MarkLabel(skipOutputInFinally)
' This is the end of the try/catch/finally block.
adderIL.EndExceptionBlock()
adderIL.BeginFinallyBlock();

// The finally block block displays a message on the TextBlock, if the 
// OutputBlock field has been set. Just as in the catch block, the following
// code tests whether the TextBlock is present, and skips the output if it is
// not present.
adderIL.Emit(OpCodes.Ldsfld, demoOutput);
adderIL.Emit(OpCodes.Ldnull);
adderIL.Emit(OpCodes.Ceq);
adderIL.Emit(OpCodes.Brtrue_S, skipOutputInFinally);

// Append a constant string to the Text property of the TextBlock.
adderIL.Emit(OpCodes.Ldsfld, demoOutput);
adderIL.Emit(OpCodes.Ldsfld, demoOutput);
adderIL.Emit(OpCodes.Callvirt, getter);
adderIL.Emit(OpCodes.Ldstr, "Executing the finally block.\n");
adderIL.Emit(OpCodes.Call, concat2);
adderIL.Emit(OpCodes.Callvirt, setter);

adderIL.MarkLabel(skipOutputInFinally);
// This is the end of the try/catch/finally block.
adderIL.EndExceptionBlock();

Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1

Platforms

Windows Phone

See Also

Reference

ILGenerator Class

System.Reflection.Emit Namespace