Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't throw exception from Rust #127

Open
gaoqiangz opened this issue Dec 20, 2021 · 4 comments
Open

can't throw exception from Rust #127

gaoqiangz opened this issue Dec 20, 2021 · 4 comments
Assignees
Labels
bug sciter-engine Issues related to the Sciter Engine itself

Comments

@gaoqiangz
Copy link

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
Copy link
Member

pravic commented Dec 28, 2021

Let me check as well. It used to work for TIS.

@SonnyX
Copy link
Contributor

SonnyX commented Dec 31, 2021

Isn't ex supposed to be of type Value rather than String?

@pravic
Copy link
Member

pravic commented Jan 1, 2022

@SonnyX not really, there's a conversion from result: https://github.com/sciter-sdk/rust-sciter/blob/master/src/value.rs#L1037

@pravic
Copy link
Member

pravic commented Jan 1, 2022

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).

@pravic pravic added bug sciter-engine Issues related to the Sciter Engine itself labels Jan 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug sciter-engine Issues related to the Sciter Engine itself
Development

No branches or pull requests

4 participants