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 handlingFilter- Condition-based exception handlingFinally- Guaranteed cleanup codeFault- Exception-only cleanup code
§IL Offset Ranges
All offsets are relative to the start of the method body’s IL code:
try_offsettotry_offset + try_lengthdefines the protected regionhandler_offsettohandler_offset + handler_lengthdefines 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
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
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
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.
Implementations§
§impl ExceptionClause
impl ExceptionClause
pub fn try_offset(&self) -> u32
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
pub fn try_length(&self) -> u32
pub fn try_end(&self) -> u32
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
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
pub fn handler_length(&self) -> u32
pub fn handler_end(&self) -> u32
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_handler(&self, offset: u32) -> bool
pub fn is_in_handler(&self, offset: u32) -> bool
pub fn is_finally(&self) -> bool
pub fn is_finally(&self) -> bool
pub fn catch_type(&self) -> Option<Token>
pub fn catch_type(&self) -> Option<Token>
pub fn filter_offset(&self) -> Option<u32>
pub fn filter_offset(&self) -> Option<u32>
§impl ExceptionClause
impl ExceptionClause
pub fn from_metadata_handler(handler: &MetadataExceptionHandler) -> Self
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>
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
impl Clone for ExceptionClause
§fn clone(&self) -> ExceptionClause
fn clone(&self) -> ExceptionClause
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for ExceptionClause
impl Debug for ExceptionClause
impl Eq for ExceptionClause
§impl PartialEq for ExceptionClause
impl PartialEq for ExceptionClause
impl StructuralPartialEq for ExceptionClause
Auto Trait Implementations§
impl Freeze for ExceptionClause
impl RefUnwindSafe for ExceptionClause
impl Send for ExceptionClause
impl Sync for ExceptionClause
impl Unpin for ExceptionClause
impl UnsafeUnpin for ExceptionClause
impl UnwindSafe for ExceptionClause
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for T
impl<T> Downcast for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.