Skip to main content

ExceptionClause

Enum ExceptionClause 

pub enum ExceptionClause {
    Catch {
        try_offset: u32,
        try_length: u32,
        handler_offset: u32,
        handler_length: u32,
        catch_type: Token,
    },
    Filter {
        try_offset: u32,
        try_length: u32,
        handler_offset: u32,
        handler_length: u32,
        filter_offset: u32,
    },
    Finally {
        try_offset: u32,
        try_length: u32,
        handler_offset: u32,
        handler_length: u32,
    },
    Fault {
        try_offset: u32,
        try_length: u32,
        handler_offset: u32,
        handler_length: u32,
    },
}
Expand description

An exception handling clause from .NET method metadata.

Exception clauses define protected regions (try blocks) and their associated handlers within a method. Each clause specifies the IL offset ranges for both the try block and the handler block.

§Clause Types

  • Catch - Type-based exception handling
  • Filter - Condition-based exception handling
  • Finally - Guaranteed cleanup code
  • Fault - Exception-only cleanup code

§IL Offset Ranges

All offsets are relative to the start of the method body’s IL code:

  • try_offset to try_offset + try_length defines the protected region
  • handler_offset to handler_offset + handler_length defines the handler

§Example

// For C# code:
// try { /* IL 0x00-0x10 */ }
// catch (Exception) { /* IL 0x10-0x20 */ }

let clause = ExceptionClause::Catch {
    try_offset: 0x00,
    try_length: 0x10,
    handler_offset: 0x10,
    handler_length: 0x10,
    catch_type: exception_type_token,
};

Variants§

§

Catch

A catch clause that handles exceptions of a specific type.

Corresponds to try { } catch (ExceptionType) { } in C#. The handler is entered if the thrown exception’s type is assignable to catch_type.

Fields

§try_offset: u32

IL offset where the try block begins.

§try_length: u32

Length in bytes of the try block.

§handler_offset: u32

IL offset where the catch handler begins.

§handler_length: u32

Length in bytes of the catch handler.

§catch_type: Token

Metadata token of the exception type to catch.

The exception is caught if its type is this type or a derived type.

§

Filter

A filter clause that handles exceptions based on a runtime condition.

Corresponds to try { } catch (Exception e) when (condition) { } in C#. The filter code is evaluated first; if it returns true (non-zero on the evaluation stack), the handler is entered.

Fields

§try_offset: u32

IL offset where the try block begins.

§try_length: u32

Length in bytes of the try block.

§handler_offset: u32

IL offset where the catch handler begins (entered if filter passes).

§handler_length: u32

Length in bytes of the catch handler.

§filter_offset: u32

IL offset where the filter code begins.

The filter code must push an integer onto the stack:

  • Non-zero (typically 1): Enter the handler
  • Zero: Continue searching for other handlers
§

Finally

A finally clause that runs regardless of whether an exception occurred.

Corresponds to try { } finally { } in C#. The handler runs on both normal exit (via leave instruction) and exception exit (during unwinding).

Fields

§try_offset: u32

IL offset where the try block begins.

§try_length: u32

Length in bytes of the try block.

§handler_offset: u32

IL offset where the finally handler begins.

§handler_length: u32

Length in bytes of the finally handler.

§

Fault

A fault clause that runs only when an exception is thrown.

Similar to finally, but only executes on the exception path. Not commonly used in C# but supported by the CLR.

Fields

§try_offset: u32

IL offset where the try block begins.

§try_length: u32

Length in bytes of the try block.

§handler_offset: u32

IL offset where the fault handler begins.

§handler_length: u32

Length in bytes of the fault handler.

Implementations§

§

impl ExceptionClause

pub fn try_offset(&self) -> u32

Gets the IL offset where the try block begins.

§Returns

The starting IL offset of the protected region.

pub fn try_length(&self) -> u32

Gets the length of the try block in bytes.

§Returns

The length of the protected region.

pub fn try_end(&self) -> u32

Gets the IL offset where the try block ends.

This is the first offset after the try block (exclusive end).

§Returns

The ending IL offset of the protected region.

pub fn handler_offset(&self) -> u32

Gets the IL offset where the handler block begins.

§Returns

The starting IL offset of the handler code.

pub fn handler_length(&self) -> u32

Gets the length of the handler block in bytes.

§Returns

The length of the handler code.

pub fn handler_end(&self) -> u32

Gets the IL offset where the handler block ends.

This is the first offset after the handler block (exclusive end).

§Returns

The ending IL offset of the handler code.

pub fn is_in_try(&self, offset: u32) -> bool

Checks if an IL offset is within the try block.

An offset is considered “in the try block” if it is greater than or equal to the try offset and less than the try end (half-open range).

§Arguments
  • offset - The IL offset to check
§Returns

true if the offset is within the protected region.

pub fn is_in_handler(&self, offset: u32) -> bool

Checks if an IL offset is within the handler block.

An offset is considered “in the handler” if it is greater than or equal to the handler offset and less than the handler end.

§Arguments
  • offset - The IL offset to check
§Returns

true if the offset is within the handler code.

pub fn is_catch(&self) -> bool

Checks if this is a catch clause.

§Returns

true if this is a Catch variant.

pub fn is_filter(&self) -> bool

Checks if this is a filter clause.

§Returns

true if this is a Filter variant.

pub fn is_finally(&self) -> bool

Checks if this is a finally clause.

§Returns

true if this is a Finally variant.

pub fn is_fault(&self) -> bool

Checks if this is a fault clause.

§Returns

true if this is a Fault variant.

pub fn catch_type(&self) -> Option<Token>

Gets the catch type token for catch clauses.

§Returns
  • Some(token) if this is a Catch clause
  • None for other clause types

pub fn filter_offset(&self) -> Option<u32>

Gets the filter offset for filter clauses.

§Returns
  • Some(offset) if this is a Filter clause
  • None for other clause types
§

impl ExceptionClause

pub fn from_metadata_handler(handler: &MetadataExceptionHandler) -> Self

Converts a metadata exception handler to an exception clause.

This method bridges the metadata representation (MetadataExceptionHandler) used during assembly loading with the emulation representation (ExceptionClause) used during runtime exception handling.

§Arguments
  • handler - The metadata exception handler to convert
§Returns

An ExceptionClause with the appropriate variant based on the handler’s flags:

pub fn from_metadata_handlers( handlers: &[MetadataExceptionHandler], ) -> Vec<Self>

Converts a slice of metadata exception handlers to exception clauses.

Convenience method for converting all exception handlers from a method’s metadata into the emulation representation.

§Arguments
  • handlers - Slice of metadata exception handlers from a method body
§Returns

A vector of exception clauses in the same order as the input handlers. The order is significant: clauses are processed innermost-first during handler search.

Trait Implementations§

§

impl Clone for ExceptionClause

§

fn clone(&self) -> ExceptionClause

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for ExceptionClause

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
§

impl Eq for ExceptionClause

§

impl PartialEq for ExceptionClause

§

fn eq(&self, other: &ExceptionClause) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
§

impl StructuralPartialEq for ExceptionClause

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Source§

fn type_name(&self) -> &'static str

Gets the type name of self
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: AsAny + ?Sized,

Source§

fn is<T>(&self) -> bool
where T: AsAny,

Returns true if the boxed type is the same as T. Read more
Source§

fn downcast_ref<T>(&self) -> Option<&T>
where T: AsAny,

Forward to the method defined on the type Any.
Source§

fn downcast_mut<T>(&mut self) -> Option<&mut T>
where T: AsAny,

Forward to the method defined on the type Any.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, A> IntoAst<A> for T
where T: Into<A>, A: Ast,

Source§

fn into_ast(self, _a: &A) -> A

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> TryClone for T
where T: Clone,

Source§

fn try_clone(&self) -> Result<T, Error>

Clones self, possibly returning an error.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more