SEH blocks are the .NET methodology for storying information about
try--catch or try--catch--finally sequences. (fault and filter are
also supported). To support SEH, one makes region boundaries in the
method body. Each region has a beginning and an ending, and regions may
be nested to allow for nesting of try--catch blocks. A region boundary
is created with a special form of the
Instruction
object constructor and added to a method.
enum iseh {
seh_try,
seh_catch,
seh_filter,
seh_fault,
seh_finally,
};
Instruction(iseh type, bool begin,
Type *catchType = nullptr);
where
catchType only needs to be specified when the block type is seh_catch.
Each region must have both a beginning and an ending. For the beginning
begin
is true, otherwise it is false. In addition there must be a try block followed by at
least one of the other block types. Note that the .net runtime does not always let
one chain multiple block types, for example a try--catch would look as follows
try begin
...
leave ...
try end
catch begin
...
leave ...
catch end
but a try--catch--finally would look as follows, to satisfy the runtime engine:
try begin
try begin
...
leave...
try end
catch begin
...
leave...
catch end
leave ...
try end
finally begin
...
endfinally ...
finally end
In addition to the above, the rules for the epilogues must also be followed in each block
(for example use leave, or endfinally) and if it is a catch block you have to pop the caught
object.