Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Debugging exceptions w/ line numbers

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

    Debugging exceptions w/ line numbers

    Hi all,

    I'm relatively new to C#, so not sure of all the ins/outs of the exception object. When exceptions occur, I'd *like* to see the detail of when/where it occurred. (Something similar to Java's very detailed PrintStackTrace.)

    So, these are exceptions being thrown *within* my code, nothing coming up from the library or other third-party code... truth is, I've been bad in writing clean code, so sometimes I get null reference exceptions. Bottom line, these are in the same function that I have the try/catch in.

    I've been using the stackframe, and calling GetLineNumber() to try to do that in C#. But not seeing the line number.. it always comes across as zero. Any suggestions?

    #2
    Hmm ... I recall a thread dealing with that issue on this forum a few weeks ago. Unfortunately I don't have a link at hand ...

    Comment


      #3
      This must be it, thanks



      Should've done a search first.

      EDIT. Maybe not, no answer in that thread either. It's definitely possible to get line numbers... this is the code source (from Google):

      StackTrace st = new StackTrace(new StackFrame(true));
      Console.WriteLine(" Stack trace for current level: {0}", st.ToString());
      StackFrame sf = st.GetFrame(0);
      Console.WriteLine(" File: {0}", sf.GetFileName());
      Console.WriteLine(" Method: {0}", sf.GetMethod().Name);
      Console.WriteLine(" Line Number: {0}", sf.GetFileLineNumber());
      Console.WriteLine(" Column Number: {0}", sf.GetFileColumnNumber());

      ... after googling a little more, it looks like the problem is our code isn't being compiled with debugging symbols.

      So the new question for you Dierk... any way for us to compile with debugging symbols? I recall you guys giving instructions on attaching to the process with VS, so I'd assume the answer is yes..
      Last edited by heech; 02-27-2009, 05:12 PM.

      Comment


        #4
        There was another one dealing with debug mode I believe...

        Comment


          #5
          Originally posted by NinjaTrader_Dierk View Post
          There was another one dealing with debug mode I believe...
          This is probably what I need to do... even though I'm not using VS, perhaps turning on debug mode will do the trick for my purpose.



          Thanks for the pointer. Hopefully it won't affect performance too dramatically.

          Comment


            #6
            Old thread but still at the top of google searches.

            Here's how I trap the indicator name and line number using try/catch and debug mode in NT8.


            Code:
            try{
            //Problem code
            } catch(Exception Err){Log(Err.ToString(), LogLevel.Warning); }
            From trace file

            With compile debug mode on contains line number
            Code:
            2022-04-22 09:31:31:426 WARNING: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative
            and less than the size of the collection. Parameter name: index    at System.ThrowHelper.ThrowArgumentOutOfRange
            Exception(ExceptionArgument argument, ExceptionResource resource)    at NinjaTrader.NinjaScript.Series`1.set_Item
            (Int32 barsAgo, T value)    at NinjaTrader.NinjaScrip[B]t.Indicators.Customized.PriceMarker.OnBarUpdate()[/B] in
            c:\Users\AdminUser\Documents\NinjaTrader 8\bin\Custom\Indicators\Customized\PriceMarker.c[B]s:line 170[/B]
            With compile debug mode off does not show line number:
            Code:
            2022-04-22 09:36:17:190 WARNING: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative
            and less than the size of the collection. Parameter name: index    at System.ThrowHelper.ThrowArgumentOutOfRange
            Exception(ExceptionArgument argument, ExceptionResource resource)    at NinjaTrader.NinjaScript.Series`1.set_Item(Int32 barsAgo, T value)    
            at NinjaTrader.NinjaScript.Indicators.Customized.PriceMarker.OnBarUpdate()

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by judysamnt7, 03-13-2023, 09:11 AM
            4 responses
            59 views
            0 likes
            Last Post DynamicTest  
            Started by ScottWalsh, Today, 06:52 PM
            4 responses
            36 views
            0 likes
            Last Post ScottWalsh  
            Started by olisav57, Today, 07:39 PM
            0 responses
            7 views
            0 likes
            Last Post olisav57  
            Started by trilliantrader, Today, 03:01 PM
            2 responses
            21 views
            0 likes
            Last Post helpwanted  
            Started by cre8able, Today, 07:24 PM
            0 responses
            10 views
            0 likes
            Last Post cre8able  
            Working...
            X