1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-05-23 19:00:13 +02:00

19 lines
368 B
Markdown
Raw Normal View History

2023-07-24 19:47:27 +02:00
# Error handling for imported Javascript methods
Javascript methods that throw can be imported in Rust like this:
```javascript
window.throwsIfPair = (num) => {
if (num % 2 === 0) throw new Error("Pair number");
return num;
};
```
```rust
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(catch)]
pub fn throwsIfPair(text: i32) -> Result<i32, JsValue>;
}
```