SEH Clause Structuring Rules

SEH Clause Structuring Rules

The rules for structuring EH clauses within a method are neither numerous nor overly complex:

All the blocks—try, filter, handler, finally, and fault—of each EH clause must be fully contained within the method code. No block can protrude from the method.

Blocks belonging to the same EH clause or different EH clauses can’t partially overlap. A block either is fully contained within another block or is completely outside it. If one guarded block (A) is contained within another guarded block (B) but is not equal to it, all handlers assigned to A must also be fully contained within B.

A handler block of an EH clause can’t be contained within a guarded block of the same clause, and vice versa. Neither can a handler block be contained in another handler block that is assigned to the same guarded block.

A filter block can’t contain any guarded blocks or handler blocks.

All blocks must start and end on instruction boundaries—that is, at offsets corresponding to the first byte of an instruction. Prefixed instructions must not be split, meaning that you can’t have constructs such as tail. .try { call }.

A guarded block must start at a code point where the evaluation stack is empty.

The same handler block can’t be associated with different guarded blocks:

.try Label1 to Label2 catch handler Label3 to Label4 .try Label4 to Label5 catch handler Label3 to Label4 // Illegal!

If the EH clause is a filter type, the filter’s actual handler must immediately follow the filter block. Since the filter block must end with the endfilter instruction, this rule can be formulated as “the actual handler starts with the instruction after endfilter.”

If a guarded block has a finally or fault handler, the same block can have no other handler. If you need other handlers, you must declare another guarded block, encompassing the original guarded block and the handler:

.try {    .try {       .try {          // Code that needs finally, catch, and fault handlers                    leave KeepGoing       }        finally {                    endfinally       }    }    catch [mscorlib]System.StackOverflowException    {              leave KeepGoing    } } fault {        endfault }



Inside Microsoft. NET IL Assembler
Inside Microsoft .NET IL Assembler
ISBN: 0735615470
EAN: 2147483647
Year: 2005
Pages: 147
Authors: SERGE LIDIN

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net