Exception Information

Created at 11 May 2020, 23:35
EY

eynt

Joined 08.05.2020

Exception Information
11 May 2020, 23:35


My code has errors inside it so in order to get as much as information as possible I catch the error and throw it back so I can see the error information:

public override void Calculate(int index)
        {
            try
            {
                Main(index);
            }
            catch (Exception e)
            {
                Print("Catched error" + Environment.NewLine + e.ToString());
            }
        }

This gives me the calling order that caused the error however not much more:

11/05/2020 20:20:47.304 | Catched error cAlgo.General+NoFlatException: Postion cannot be flat. GetHL    at cAlgo.General.GetHLByIndex(MarketPosition position, Int32 index)    at cAlgo.TrendHL.PlotSet()    at cAlgo.TrendHL.NewPick(Int32 index)    at cAlgo.TrendHL.Main(Int32 index)    at cAlgo.TrendHL.Calculate(Int32 index)

 

I'd like to get more information. for example the lines number where the error occurd. Something similar to:

Catched error
System.DivideByZeroException: Attempted to divide by zero.
   at NinjaTrader.Indicator.aaaTestInd.main() in c:\Users\yuval\Documents\NinjaTrader 7\bin\Custom\Indicator\aaaTestInd.cs:line 61
   at NinjaTrader.Indicator.aaaTestInd.OnBarUpdate() in c:\Users\yuval\Documents\NinjaTrader 7\bin\Custom\Indicator\aaaTestInd.cs:line 69

 

Thanks


@eynt
Replies

PanagiotisCharalampous
12 May 2020, 09:13

Hi Yuval,

The Exception class provides more useful information that you can use. See below an example

            try
            {
                Main(index);
            } 
            catch (Exception e)
            {
                Print("Catched error: " + e.ToString());
                Print("Inner Exception: " + e.InnerException.ToString());
                Print("Messsage: " + e.Message.ToString());
                Print("Stack Trade: " + e.StackTrace.ToString());
            }

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

eynt
12 May 2020, 10:21

RE:

Thank you

 

That did not added more information. The information I'm interested in is the line number where the error happened and the line numbers of the called funstions.

For example, the function Calculate called the function Main at line X and Main called NewRevesedPick at line Y and so on until I can see that the error was raised at the function GetHLByIndex at line Z.

At the moment I get this:

 

12/05/2020 07:12:52.244 | Stack Trade:    at cAlgo.General.GetHLByIndex(MarketPosition position, Int32 index)    at cAlgo.TrendHL.PlotSet()    at cAlgo.TrendHL.NewRevesedPick(Double reversedPrice, MarketPosition Position, Int32 index)    at cAlgo.TrendHL.Main(Int32 index)    at cAlgo.TrendHL.Calculate(Int32 index)

12/05/2020 07:12:52.228 | Messsage: Postion cannot be flat. GetHL

12/05/2020 07:12:52.228 | Inner Exception: null

12/05/2020 07:12:52.228 | Catched error: cAlgo.General+NoFlatException: Postion cannot be flat. GetHL    at cAlgo.General.GetHLByIndex(MarketPosition position, Int32 index)    at cAlgo.TrendHL.PlotSet()    at cAlgo.TrendHL.NewRevesedPick(Double reversedPrice, MarketPosition Position, Int32 index)    at cAlgo.TrendHL.Main(Int32 index)    at cAlgo.TrendHL.Calculate(Int32 index)
 

 

Here is an example of an error I got on a WinForm Application which shows what i mean:

 

 

System.IO.IOException: The process cannot access the file 'C:\Users\yuval\Documents\cAlgo\Sources\Indicators\TrendHL\.vs\TrendHL\v16\Server\sqlite3\db.lock' because it is being used by another process.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite)
   at System.IO.FileInfo.CopyTo(String destFileName, Boolean overwrite)
   at ManagerRobot.Form1.DirectoryCopy(String sourceDirName, String destDirName, Boolean overwrite, Boolean excludeAt, Boolean excludeByDate) in D:\BTSync\BT Sync Robot\BTSync Robot HERE\RobotFiles\Projects\ManagerRobot\ManagerRobot\Form1.cs:line 683
   at ManagerRobot.Form1.DirectoryCopy(String sourceDirName, String destDirName, Boolean overwrite) in D:\BTSync\BT Sync Robot\BTSync Robot HERE\RobotFiles\Projects\ManagerRobot\ManagerRobot\Form1.cs:line 634
   at ManagerRobot.Form1.DirectoryCopy(String sourceDirName, String destDirName, Boolean overwrite, Boolean excludeAt, Boolean excludeByDate) in D:\BTSync\BT Sync Robot\BTSync Robot HERE\RobotFiles\Projects\ManagerRobot\ManagerRobot\Form1.cs:line 697
   at ManagerRobot.Form1.DirectoryCopy(String sourceDirName, String destDirName, Boolean overwrite) in D:\BTSync\BT Sync Robot\BTSync Robot HERE\RobotFiles\Projects\ManagerRobot\ManagerRobot\Form1.cs:line 634
   at ManagerRobot.Form1.DirectoryCopy(String sourceDirName, String destDirName, Boolean overwrite, Boolean excludeAt, Boolean excludeByDate) in D:\BTSync\BT Sync Robot\BTSync Robot HERE\RobotFiles\Projects\ManagerRobot\ManagerRobot\Form1.cs:line 697
   at ManagerRobot.Form1.DirectoryCopy(String sourceDirName, String destDirName, Boolean overwrite) in D:\BTSync\BT Sync Robot\BTSync Robot HERE\RobotFiles\Projects\ManagerRobot\ManagerRobot\Form1.cs:line 634
   at ManagerRobot.Form1.DirectoryCopy(String sourceDirName, String destDirName, Boolean overwrite, Boolean excludeAt, Boolean excludeByDate) in D:\BTSync\BT Sync Robot\BTSync Robot HERE\RobotFiles\Projects\ManagerRobot\ManagerRobot\Form1.cs:line 697
   at ManagerRobot.Form1.DirectoryCopy(String sourceDirName, String destDirName, Boolean overwrite) in D:\BTSync\BT Sync Robot\BTSync Robot HERE\RobotFiles\Projects\ManagerRobot\ManagerRobot\Form1.cs:line 634
   at ManagerRobot.Form1.DirectoryCopy(String sourceDirName, String destDirName, Boolean overwrite, Boolean excludeAt, Boolean excludeByDate) in D:\BTSync\BT Sync Robot\BTSync Robot HERE\RobotFiles\Projects\ManagerRobot\ManagerRobot\Form1.cs:line 697
   at ManagerRobot.Form1.DirectoryCopy(String sourceDirName, String destDirName, Boolean overwrite) in D:\BTSync\BT Sync Robot\BTSync Robot HERE\RobotFiles\Projects\ManagerRobot\ManagerRobot\Form1.cs:line 634
   at ManagerRobot.Form1.DirectoryCopy(String sourceDirName, String destDirName, Boolean overwrite, Boolean excludeAt, Boolean excludeByDate) in D:\BTSync\BT Sync Robot\BTSync Robot HERE\RobotFiles\Projects\ManagerRobot\ManagerRobot\Form1.cs:line 697
   at ManagerRobot.Form1.DirectoryCopy(String sourceDirName, String destDirName, Boolean overwrite) in D:\BTSync\BT Sync Robot\BTSync Robot HERE\RobotFiles\Projects\ManagerRobot\ManagerRobot\Form1.cs:line 634
   at ManagerRobot.Form1.DirectoryCopy(String sourceDirName, String destDirName, Boolean overwrite, Boolean excludeAt, Boolean excludeByDate) in D:\BTSync\BT Sync Robot\BTSync Robot HERE\RobotFiles\Projects\ManagerRobot\ManagerRobot\Form1.cs:line 697
   at ManagerRobot.Form1.BackupDirectory(String timeStamp, String sourcePath, Boolean excludeByDate) in D:\BTSync\BT Sync Robot\BTSync Robot HERE\RobotFiles\Projects\ManagerRobot\ManagerRobot\Form1.cs:line 726
   at ManagerRobot.Form1.BackupCode(Boolean excludeByDate) in D:\BTSync\BT Sync Robot\BTSync Robot HERE\RobotFiles\Projects\ManagerRobot\ManagerRobot\Form1.cs:line 797
   at ManagerRobot.Form1.btnCustomToBackup_Click(Object sender, EventArgs e) in D:\BTSync\BT Sync Robot\BTSync Robot HERE\RobotFiles\Projects\ManagerRobot\ManagerRobot\Form1.cs:line 788
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

 


@eynt

eynt
14 May 2020, 09:13

RE: RE:

Hello

 

Is there anything new about the subject? I can't stress how important this issue is to me.

 

Thanks


@eynt

PanagiotisCharalampous
14 May 2020, 09:38

Hi Yuval,

This is not a cTrader issue but a general .Net question. You can consider looking for an answer in .Net forums as well.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous