veewee/ext-wasm

Custom exceptions

Opened this issue · 0 comments

Currently this repo throws a default PHP \Exception.
It should be better if we at-least provided a Wasm\Exception

Other possible exceptions:

Do note that currently we'll need to work around these limitations:

static mut WASM_EXCEPTION: Option<&'static ClassEntry> = None;

#[php_startup]
pub fn startup() {
    let ce_wasm_exception = ClassBuilder::new("Wasm\\Exception\\Exception")
        .extends(ce::exception())
        .build()
        .expect("Invalid check");
    unsafe { WASM_EXCEPTION.replace(ce_wasm_exception) };
}

//--> Return
PhpException::new(e.to_string(), 0, unsafe {
    WASM_EXCEPTION.expect("did not set exception ce")
})