Custom exceptions
Opened this issue · 0 comments
veewee commented
Currently this repo throws a default PHP \Exception
.
It should be better if we at-least provided a Wasm\Exception
Other possible exceptions:
- https://developer.mozilla.org/en-US/docs/WebAssembly/JavaScript_interface/Exception
- https://developer.mozilla.org/en-US/docs/WebAssembly/JavaScript_interface/CompileError
- https://developer.mozilla.org/en-US/docs/WebAssembly/JavaScript_interface/LinkError
- https://developer.mozilla.org/en-US/docs/WebAssembly/JavaScript_interface/RuntimeError
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")
})