QtScript Error objects

  • Hi forum,
    Making applications scriptable document describes in the last section about Error object. It says:

    This function returns a human-readable backtrace, in the form of an array of strings.
    Error objects have the following additional properties:
    lineNumber: The line number where the error occurred.
    fileName: The file name where the error occurred (if a file name was passed to QScriptEngine::evaluate()).
    stack: An array of objects describing the stack. Each object has the following properties:
    functionName: The function name, if available.
    fileName: The file name, if available.
    lineNumber: The line number, if available."

    I have this code which I added in qtscript helloscript example(helloscript.js file)//does nothing but executes the program line by line...
    @function bar(){
    try{ Tag.nonsense = 83 ;}
    catch (e){this.err = e; print(e instanceof Error);//true}
    var x = bar();
    print(this.err);//ReferenceError: Can't find variable: Tag

    The outputs I have written in comments. Clearly this is a departure from what is written in the document as the error object having those properties. What am i missing??

  • Hello, ~pkj__!

    I think that your problem lies in Tag object. Try to append to your code line:
    var Tag = {};

    It should create object tag and you won't have any errors. Now, you get this error because you don't have variable Tag. If you want to enable it in C++ code, you should set QObject::objectName, another way - you should init it in js code.

  • I introduced the Tag, knowing that it will give error. My question is not why the error is being shown. Albeit, why is it that errorObject.backtrace is showing undefined. It has been mentioned in "making applications scriptable" document that Error objects have backtrace as a prototype property.

  • Hmm.. It looks strange. AFAIK, this coe must work.

    But Chrome can't get x.backtrace also.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.