Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT8b9 Exception handling (general)

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

    NT8b9 Exception handling (general)

    While developing new NinjaScripts (mostly Indicators) I have experienced quite a lot of stalling and crashing. Whenever this happens (and that usually forces me to kill NT process completely) and I start debugging in VS the problem is always with some unhandled exception, whether it is NullReference, ArgumentOutOfRange or whatever else.

    The stalling/crashing happens often enough to make me think development without Visual Studio for debugging is at the moment virtually impossible.

    Is this problem recognized and addressed by the development team or am I exceptional with my issues?

    #2
    I've only had 2 indicators custom, and over 200 strategies (mostly same code base)


    The only exceptions I get are in their code.

    Do you only have 1 work space open at a time? Close any that are not in use.

    Not using VS here.

    Comment


      #3
      Thanks sledge, yes I do happen to have 1+ workspace open at a time, I will try to make sure other ones are closed.

      In the meantime what would happen if eg.
      1. You try to edit a dictionary that you forgot to instantiate
      2. You try to get the value with out of range index, eg: mySeries[-1]

      In my case the chart simply stalls and to get what is the error/exception I need to debug with VS.

      Comment


        #4
        Originally posted by gregid View Post
        2. You try to get the value with out of range index, eg: mySeries[-1]

        .


        I have something in a strategy that is randomly happening on a contract startup. I replay from es03-14 post zenfire collapse.

        Sometimes it is fine, doesn't hapen. Then next replay run, a strategy disables because of the error. The chart is fine which had the indicator, and works.



        Comment


          #5
          I just got another of the stall/crash type. This time I got an error message in the Log:
          "A hosted indicator tried to load additional data. All data must be first loaded by the hosting NinjaScript in its configure state"

          The error itself is quite clear - but the crash is not what I expect. This time just one workspace open.

          Comment


            #6
            It looks like NT staff was able to replicate it in B6... no tracking # provided so who knows what happened to it.

            Comment


              #7
              Originally posted by gregid View Post
              I just got another of the stall/crash type. This time I got an error message in the Log:
              "A hosted indicator tried to load additional data. All data must be first loaded by the hosting NinjaScript in its configure state"

              The error itself is quite clear - but the crash is not what I expect. This time just one workspace open.
              What about using try/catch?
              In most cases, it can prevent a platform crash.
              ninZa
              NinjaTrader Ecosystem Vendor - ninZa.co

              Comment


                #8
                Originally posted by ninZa View Post
                What about using try/catch?
                In most cases, it can prevent a platform crash.
                I tend to use try/catch for anything non-standard... but since I have never had to do it for typical operations in NT it didn't cross my mind to use it more liberally so thanks for suggestion!

                Comment


                  #9
                  Since I put entire OnBarUpdate inside try/catch my NT doesn't crash any more on the simple exceptions. I do hope however these exceptions will be handled by core code and base classes in the final release as they were handled properly in NT7.

                  Comment


                    #10
                    Originally posted by sledge View Post
                    It looks like NT staff was able to replicate it in B6... no tracking # provided so who knows what happened to it.

                    http://ninjatrader.com/support/forum...dditional+data
                    As far as this is concerned, this is expected. Please see my post at the following link and let me know if you have any questions.

                    Comment


                      #11
                      Hi Patrick - could you also address the main topic of this thread - which is lack of exception handling by NT8.

                      Comment


                        #12
                        Hello gregid,

                        Thank you for your patience.

                        What specific exceptions are missed by NinjaTrader and caught by Visual Studio in this scenario?

                        Comment


                          #13
                          Originally posted by NinjaTrader_PatrickH View Post
                          Hello gregid,

                          Thank you for your patience.

                          What specific exceptions are missed by NinjaTrader and caught by Visual Studio in this scenario?
                          As mentioned in the first post the two most obvious are:
                          - NullReference (eg. editing an object with no instance created beforehand)
                          - ArgumentOutOfRange (eg. MySeries[-1])

                          But more generally I don't see any fallback exception handling, ie.: something that would protect from stalling/crash when the exact exception handling is not in place. For example in my current code I use the following:
                          Code:
                          [FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]protected [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]override [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] OnBarUpdate()[/SIZE][/FONT]
                          [SIZE=2][FONT=Consolas]{[/FONT][/SIZE]
                          [/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]   try[/COLOR][/SIZE][/FONT]
                          [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]   {[/SIZE][/FONT]
                          [SIZE=2][FONT=Consolas]       SafeOnBarUpdate();[/FONT][/SIZE]
                          [SIZE=2][FONT=Consolas]   }[/FONT][/SIZE]
                          [/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]   catch[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] ([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Exception[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] ex)[/SIZE][/FONT]
                          [SIZE=2][FONT=Consolas]   {[/FONT][/SIZE]
                          [SIZE=2][FONT=Consolas]       Print(ex);[/FONT][/SIZE]
                          [SIZE=2][FONT=Consolas]   }[/FONT][/SIZE]
                          [SIZE=2][FONT=Consolas]}[/FONT][/SIZE]
                          [/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]private [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] SafeOnBarUpdate()[/SIZE][/FONT]
                          [SIZE=2][FONT=Consolas]{[/FONT][/SIZE]
                          [SIZE=2][FONT=Consolas]   [FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000][FONT=Consolas][SIZE=2][COLOR=#008000]//all the OnBarUpdate logic here[/COLOR][/SIZE][/FONT]
                          [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]}
                          [/FONT][/SIZE][/SIZE][/FONT]
                          This simple fallback saves me a lot of trouble and as much as I can continue using it I raise it as potential issue in the final release. I would suggest this (fallback) could be done from the base class level.
                          Last edited by gregid; 03-08-2016, 02:59 PM.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by sidlercom80, 10-28-2023, 08:49 AM
                          166 responses
                          2,234 views
                          0 likes
                          Last Post sidlercom80  
                          Started by thread, Yesterday, 11:58 PM
                          0 responses
                          1 view
                          0 likes
                          Last Post thread
                          by thread
                           
                          Started by jclose, Yesterday, 09:37 PM
                          0 responses
                          6 views
                          0 likes
                          Last Post jclose
                          by jclose
                           
                          Started by WeyldFalcon, 08-07-2020, 06:13 AM
                          10 responses
                          1,414 views
                          0 likes
                          Last Post Traderontheroad  
                          Started by firefoxforum12, Yesterday, 08:53 PM
                          0 responses
                          11 views
                          0 likes
                          Last Post firefoxforum12  
                          Working...
                          X