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: TokenThe type token of the exception being handled.
current_location: InstructionLocationThe location where the exception was thrown.
frames: Vec<FrameSearchInfo>Stack frames to search, ordered deepest (innermost) first.
current_frame: usizeIndex 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
impl HandlerSearchState
pub fn new(exception_type: Token, throw_location: InstructionLocation) -> Self
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 exceptionthrow_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>,
)
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 frameoffset- The IL offset within the methodclauses- The exception clauses defined in this method
pub fn is_complete(&self) -> bool
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
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>
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
impl Clone for HandlerSearchState
§fn clone(&self) -> HandlerSearchState
fn clone(&self) -> HandlerSearchState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for HandlerSearchState
impl RefUnwindSafe for HandlerSearchState
impl Send for HandlerSearchState
impl Sync for HandlerSearchState
impl Unpin for HandlerSearchState
impl UnwindSafe for HandlerSearchState
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more