Question How to know the exact line of code from where the exception is thrown?

rdevisetti

New member
Joined
Mar 6, 2017
Messages
1
Location
Bangalore, India
Programming Experience
3-5
Hi All,

Please let me know the ways to find the exact line of code from where the exception is thrown in .Net Compact Framework. When I tried I am not seeing the line number details for some reason. Sometimes it displays. After printing the exception message and StackTrace it is showing the following.... But in some case it is just displaying "Object value is not set to a reference" if an object is not initialized, but not showing the object name also. But there is no way for me to know which object is not initialized if the code is little big...like 20 to 30 lines of code...


exception trace is at HdPsTest.ControlSystemHdPsXxx.CreateDeviceCmd(String args)
at Crestron.SimplSharpProInternal.SimplSharpProManager.CustomApplicationCMDProcessorRxThread()

The Code I used to generate the exception is as follows....

public void CreateDeviceCmd(String args)
{
try
{
int[] arr = {1, 2, 34};
CrestronConsole.PrintLine("arr[{0}] is {1}", 5, arr[5]);
}
catch (Exception ex)
{
CrestronConsole.PrintLine("lineNumber is {0}\r\n, exception trace is {1}\r\n, exception message is {2}", lineNumber, ex.StackTrace, ex.Message);
}
}
 
Last edited:

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
3,381
Location
Chesapeake, VA
Programming Experience
10+
If you build with debug symbols, the exception stack trace ships include the line numbers.
 
Top Bottom