Announcement

Collapse
No announcement yet.

No error message for missing method????

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • No error message for missing method????

    I (accidentally) referenced a method in an object for which it wasn't defined. Code following that line does not execute, but I get no error message. This makes it very difficult (time consuming) to debug. Why is there no error message? I can't believe this is an unfixed bug, so why am I suffering (build 782)?
    And even more strange is what happens when I do add the missing method - then I do get a message to say it doesn't exist!!!!!! How can that happen?

    This is my day one of EFS writing and I get two (see earlier post) weird, time-wasting, "bugs". What am I doing wrong?

    Later - a PS: I noticed that where I called the missing method I had omitted the argument (name = mark), but no error I see, JavaScript is too lax for my liking! Having put that argument in I no longer see "Printtest undefined" - of course "undefined" referred to the argument, not the method. However this still leaves me puzzling over how to cope with missing methods and the lack of any error message.

    PHP Code:
    var bStudyInit false
    var 
    asipsOneSymSet null;

    // function for method
    function Printtest2(mark) {
        
    debugPrint("Printtest " mark "\n");
        }


    // make object    
    function SymInvPair(sSymnInv) { //
       
    this.sSym sSym;
       
    this.nInv nInv;
       
    this.Printtest Printtest2;
       
       
    this.Printtest("sip Constructor");
       
    debugPrint("SIP:  " this.sSym "," this.nInv "  \n");

    }

    // make another object, unlike "SymInvPair" this one has no method "Printtest", BUT when I call the (missing) method the program "hangs", and does not error.
    // HOWEVER, when I do add the method (just duplicate the " this.Printtest = Printtest2;" line from above I then get an error message "Printtest undefined". This is really incomprehensible - I now get the error message I expect when there is an error when the error doesn't exist?????
    function SymInvSet(Sym) {       // Type is  "sis"
       
    this.sip60 = new SymInvPair(Sym,60);
    }


    function 
    preMain() {
        
    setStudyTitle("Test1 - No error for missing method");
        
    setCursorLabelName("Test1");
    }


    function 
    main() {

        if ( 
    bStudyInit == false ) { 
               
            
    asipsOneSymSet = new SymInvSet(getSymbol());
            
    debugPrint("Script is loading 2\n"); 
            
    bStudyInit true
       } 
        
        if (
    getBarState() == BARSTATE_ALLBARS) {
            return;
        }
        
         
        if (
    getBarState() == BARSTATE_NEWBAR) {
            
    debugPrint("The first tick of a new bar has arrivedA\n");
            
    asipsOneSymSet.Printtest();  // By accident this references a method that does not exist (in this object). I get no error message!!!!! 
                                        // The program does not execute this following line, how am I meant to detect this type of error?
                                        // (See debug output is just the line "The first tick of a new bar has arrivedA", not the "B" version)
                                       // If I add the missing method to SymInvSet I get the totaly unexpected "Printtest undefined" message!!!!
             
    debugPrint("The first tick of a new bar has arrivedB\n");
        }   
        
       return 
    0;


    Last edited by Dave180; 05-22-2007, 03:38 AM.

  • #2
    Re: No error message for missing method????

    Dave180,


    Originally posted by Dave180
    I (accidentally) referenced a method in an object for which it wasn't defined. Code following that line does not execute, but I get no error message. This makes it very difficult (time consuming) to debug. Why is there no error message? I can't believe this is an unfixed bug, so why am I suffering (build 782)?
    And even more strange is what happens when I do add the missing method - then I do get a message to say it doesn't exist!!!!!! How can that happen?

    This is my day one of EFS writing and I get two (see earlier post) weird, time-wasting, "bugs". What am I doing wrong?

    Later - a PS: I noticed that where I called the missing method I had omitted the argument (name = mark), but no error I see, JavaScript is too lax for my liking! Having put that argument in I no longer see "Printtest undefined" - of course "undefined" referred to the argument, not the method. However this still leaves me puzzling over how to cope with missing methods and the lack of any error message.

    There are a couple issues here. First, the issue regarding the error message. I have also experienced similar situations where you have to extract the reason for a code error (in efs-JavaScript as well as C#). In efs-JavaScript, the error usually behaves similarly to a break; statement and directly exits the conditional block. While the I am not sure exactly why this occurs, there is documentation on the web regarding hidden errors in Javascript. What I have read is that you must be careful when declaring variables and objects in blocks or otherwise nested scope.

    I believe the reason is in part due to the scope of the object and the error causing a rift in the JavaScript object closure. Perhaps this is creating an error that occurs outside of the scope of the error handler. There are likely alternate explanations that may be better than my conjecture, but I am pretty sure it is due to unexpected object scoping issues. I can only offer my experience on similar issues. Regardless, being aware of the potential, and the use methodical troubleshooting will allow you to readily identify these situations.

    Second, as for your object, this is my interpretation of the members

    asipsOneSymSet.sip60.sSym
    asipsOneSymSet.sip60.nInv
    asipsOneSymSet.sip60.Printtest //points to function Printtest2()

    In the efs you posted, you called asipsOneSymSet.Printtest, which in fact does not exist.

    Unlike other class based languages, JavaScript is an object based language with prototypical inheritance, where classes can only be simulated. While this is a bit different and can take some time to become adept, it is forgiving and very easy to write simple code. Having used it several years, I have found it to be flexible and much more powerful than than I had previously believed. Hopefully you can get past your reservations in the first day writing efs code...

    Comment


    • #3
      Steve, Hi, thanks for the background. JavaScript is not something I've used before, I'm just being imaginative and treating it as a "dialect" of C++ & VB for now - and have made good progress today with multiple series and objects and images on screen working nicely (well, slow to load), but agreed quite powerful.

      But my "suck it and see" approach it is so much more productive if you get clear errors (and an integrated debug/edit/continue ide would help!). So thanks for pointing out that I shall have to "watch my own back" rather than expecting the tools to do it for me! I still find it bizarre that you don't get an error for a missing member!

      Thanks again.

      Comment


      • #4
        Dave,

        I've learned to put try/catch blocks around my code as I'm developing it. In the catch section I print out the exception which usually gives you a good description of what went wrong.

        I too have had my share of "early exits" in the code. Basically when JavaScript hits an exception it treats it as a return.

        Steve

        Comment


        • #5
          Hi Dave,

          You are most welcome. JavaScript is quite similar to several other languages but is definately its own language insomuch that it is designed to operate within a host environment/object using just in time compilation. Here is an interesting article that discusses the inherant flexibility in the platform - http://www.manageability.org/blog/st...-of-javascript

          After reading my response, I wanted to clarify that my experience is that the compiler throws errors correctly 99% of the time (or more). My discussion was based on those times where the error is not thrown.

          As for using try/catch blocks as smeyer55 noted, this is a great practice and I second his recommendation. I have tried to use these in the past in an attempt to catch the 'hidden' errors we have discussed, but as I remember, my results were mixed. Regardless, I also use the try/catch blocks. They are a great tool to have and may be used for either fault tolerant code, the exception information they provide or both.

          Comment

          Working...
          X