Skip to main content

ExceptionObserver

Trait ExceptionObserver 

Source
pub trait ExceptionObserver: 'static {
    // Required method
    fn on_exception(&self, exception: &ExceptionInfo);
}
Available on crate feature observer only.
Expand description

Trait for observing PHP exceptions.

§Lifecycle

on_exception is called whenever an exception is thrown in PHP, before any catch blocks are evaluated.

§Thread Safety

Observer must be Send + Sync. Use thread-safe primitives for mutable state.

§Example

ⓘ
use ext_php_rs::prelude::*;
use std::sync::atomic::{AtomicU64, Ordering};

struct ExceptionCounter {
    count: AtomicU64,
}

impl ExceptionObserver for ExceptionCounter {
    fn on_exception(&self, exception: &ExceptionInfo) {
        self.count.fetch_add(1, Ordering::Relaxed);
        eprintln!("Exception #{}: {}",
            self.count.load(Ordering::Relaxed),
            exception.class_name
        );
    }
}

Required Methods§

Source

fn on_exception(&self, exception: &ExceptionInfo)

Called when an exception is thrown.

This is called at throw time, before any catch blocks are evaluated. The exception may or may not be caught.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§