Skip to main content

HandlerSearchState

Struct HandlerSearchState 

pub struct HandlerSearchState {
    pub exception_type: Token,
    pub current_location: InstructionLocation,
    pub frames: Vec<FrameSearchInfo>,
    pub current_frame: usize,
    pub pending_cleanup: Vec<HandlerMatch>,
    pub handler_found: Option<HandlerMatch>,
}
Expand description

State for multi-frame exception handler search across the call stack.

When an exception is thrown, the handler search may span multiple stack frames. This structure tracks the state of that search, including which frames have been searched, what cleanup handlers have been found, and whether a catch handler has been located.

§Usage

let mut state = HandlerSearchState::new(exception_type, throw_location);

// Add frames from the call stack (deepest first)
state.add_frame(method1, offset1, clauses1);
state.add_frame(method2, offset2, clauses2);

// Search proceeds until a handler is found or all frames are exhausted
while !state.is_complete() {
    // Process each frame...
}

Fields§

§exception_type: Token

The type token of the exception being handled.

§current_location: InstructionLocation

The location where the exception was thrown.

§frames: Vec<FrameSearchInfo>

Stack frames to search, ordered deepest (innermost) first.

§current_frame: usize

Index of the current frame being searched (0-based).

§pending_cleanup: Vec<HandlerMatch>

Cleanup handlers (finally/fault) collected during the search.

These handlers must execute before entering a catch handler or before propagating the exception to the next frame.

§handler_found: Option<HandlerMatch>

The catch or filter handler that will handle the exception, if found.

Implementations§

§

impl HandlerSearchState

pub fn new(exception_type: Token, throw_location: InstructionLocation) -> Self

Creates a new handler search state for an exception.

Initializes the search state with the exception type and the location where the exception was thrown. Stack frames should be added using add_frame before searching.

§Arguments
  • exception_type - The type token of the thrown exception
  • throw_location - The instruction location where the exception was thrown
§Returns

A new HandlerSearchState ready to accept stack frames for searching.

pub fn add_frame( &mut self, method: Token, offset: u32, clauses: Vec<ExceptionClause>, )

Adds a stack frame to the search.

Frames should be added in order from innermost (current) to outermost (caller). Each frame’s exception clauses will be searched for handlers.

§Arguments
  • method - The method token for this frame
  • offset - The IL offset within the method
  • clauses - The exception clauses defined in this method

pub fn is_complete(&self) -> bool

Checks if the handler search is complete.

The search is complete when either:

  • A matching handler has been found
  • All frames have been searched without finding a handler
§Returns

true if the search is complete, false if more frames need to be searched.

pub fn has_pending_cleanup(&self) -> bool

Checks if there are pending cleanup handlers to execute.

Cleanup handlers (finally/fault blocks) must be executed before entering a catch handler or before continuing to unwind to the next frame.

§Returns

true if there are cleanup handlers waiting to be executed.

pub fn take_next_cleanup(&mut self) -> Option<HandlerMatch>

Takes the next cleanup handler from the queue.

Removes and returns the first pending cleanup handler. Cleanup handlers should be executed in the order they are returned (FIFO).

§Returns

The next cleanup handler to execute, or None if no cleanup handlers remain.

Trait Implementations§

§

impl Clone for HandlerSearchState

§

fn clone(&self) -> HandlerSearchState

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
§

impl Debug for HandlerSearchState

§

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

Formats the value using the given formatter. Read more

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> 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<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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<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> Same for T

Source§

type Output = T

Should always be Self
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, 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.