Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Promise exception is not pass to .catch method.
QtWS25 Last Chance

Promise exception is not pass to .catch method.

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qjsenginepromisejavascript
1 Posts 1 Posters 532 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Willie Huang
    wrote on 16 Sept 2019, 08:25 last edited by Willie Huang
    #1

    Hi, guys,

    I'm using QJSEngine in my product to run JS codes for some automation purpose on Qt 5.12.1. And there are some codes that leverages the Promise object provided by QJSEngine. And I got some strange result there.
    Here is my testing code:

    new Promise(function (resolve, reject) { resolve("OK")})
        .then(function(){JSON.parse("")});
    

    This above snippet code runs by QJSEngine::evaluate() method.
    The result I got is: [object Promise]
    The expected result should be: SyntaxError: JSON.parse: Parse error

    And when you run above code second time, you will get the error.
    But this is wrong. I want the first time run, it returns me the error message, not second time.

    If you run above code in chrome console, then it returns correct result.

    Also if you add a .catch (function(e) {console.log("JSON parse error.")}); at then end of above testing code to make it chained at the end of the promise. it will also not print the log message.

    Does anyone know what happened in the QJSEngine?

    1 Reply Last reply
    0

    1/1

    16 Sept 2019, 08:25

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved