Skip to content

Latest commit

 

History

History
30 lines (22 loc) · 2.02 KB

ii.19-exception-handling.md

File metadata and controls

30 lines (22 loc) · 2.02 KB

II.19 Exception handling

In the CLI, a method can define a range of CIL instructions that are said to be protected. This is called a try block. It can then associate one or more handlers with that try block. If an exception occurs during execution anywhere within the try block, an exception object is created that describes the problem. The CLI then takes over, transferring control from the point at which the exception was thrown, to the block of code that is willing to handle that exception. See Partition I.

No two handlers (fault, filter, catch, or finally) can have the same starting address. When an exception occurs it is necessary to convert the execution address to the correct most lexically nested try block in which the exception occurred.

SEHBlock ::=
TryBlock SEHClause [ SEHClause* ]

The next few subclauses expand upon this simple description, by describing the five kinds of code block that take part in exception processing: try, catch, filter, finally, and fault. (Note that there are restrictions upon how many, and what kinds of SEHClause a given TryBlock can have; see Partition I for details.)

The remaining syntax items are described in detail below; they are collected here for reference.

TryBlock ::= Description
.try Label to Label Protect region from first label to prior to second
| .try ScopeBlock ScopeBlock is protected
SEHClause ::= Description
catch TypeReference HandlerBlock Catch all objects of the specified type
| fault HandlerBlock Handle all exceptions but not normal exit
| filter Label HandlerBlock Enter handler only if filter succeeds
| finally HandlerBlock Handle all exceptions and normal exit
HandlerBlock ::= Description
handler Label to Label Handler range is from first label to prior to second
| ScopeBlock ScopeBlock is the handler block