can't throw exception from Rust
gaoqiangz opened this issue · 4 comments
gaoqiangz commented
rust:
impl Frame {
fn throw(&self, ex: String) -> Result<(),String> {
Err(ex)
}
}
impl EventHandler for Frame {
displatch_script_call! {
fn throw(Value);
}
}
js:
try {
Window.this.xcall("throw","exception");
} catch(ex) {
console.log(ex);
}
pravic commented
Let me check as well. It used to work for TIS.
SonnyX commented
Isn't ex
supposed to be of type Value
rather than String
?
pravic commented
@SonnyX not really, there's a conversion from result: https://github.com/sciter-sdk/rust-sciter/blob/master/src/value.rs#L1037
pravic commented
I confirm, it doesn't work in JS.
try {
stdout.println("call", view.throw());
}
catch(e) {
stdout.println("exception", e);
}
try {
console.log("call", Window.this.xcall("throw"));
} catch(e) {
console.log("exception", e);
}
It prints "exception" in TIS but "call" in JS.
@c-smile Andrew, we initialize an exception here similar to value::make_error
by calling ValueStringDataSet
with UT_STRING_ERROR
. It used to work in TIScript but doesn't work in JS (and seems has never been working judging by to a quick pick of several JS versions).