共用方式為


ILGenerator.BeginCatchBlock Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Begins a catch block.

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

Syntax

'Declaration
Public Overridable Sub BeginCatchBlock ( _
    exceptionType As Type _
)
public virtual void BeginCatchBlock(
    Type exceptionType
)

Parameters

  • exceptionType
    Type: System.Type
    The type of the exception that is caught.

Exceptions

Exception Condition
ArgumentException

The catch block is within a filtered exception.

ArgumentNullException

exceptionType is nulla null reference (Nothing in Visual Basic), and the exception filter block has not returned a value that indicates that finally blocks should be run until this catch block is located.

NotSupportedException

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

Remarks

Emits a branch instruction to the end of the current exception block.

NoteNote:

If the filter exception block returns the constant exception_execute_handler, the argument to the BeginCatchBlock is not checked. For more information, see the Common Language Infrastructure documentation. The documentation is available online; see ECMA C# and Common Language Infrastructure Standards on MSDN and Standard ECMA-335 - Common Language Infrastructure (CLI) on the Ecma International Web site.

Examples

The following example demonstrates the use of the BeginCatchBlock method. This code is part of a larger example provided for the BeginExceptionBlock method.

' Use the Leave instruction to exit a try block. You cannot branch from try
' blocks.
adderIL.Emit(OpCodes.Leave, exTryCatchFinally) 


' Start the catch block for OverflowException.
'
adderIL.BeginCatchBlock(overflowType)

' On entry to the catch block, the thrown exception is on the stack. Store it

' in a local variable.
adderIL.Emit(OpCodes.Stloc_S, thrownException)
// Use the Leave instruction to exit a try block. You cannot branch from try
// blocks.
adderIL.Emit(OpCodes.Leave, exTryCatchFinally);


// Start the catch block for OverflowException.
//
adderIL.BeginCatchBlock(overflowType);

// On entry to the catch block, the thrown exception is on the stack. Store it
// in a local variable.
adderIL.Emit(OpCodes.Stloc_S, thrownException);

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.