C
C#3w ago
Faker

How to read stack trace errors

Hello guys, consider the following error:
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at DataStructure.LinkedLists`1.AddNode(T data) in C:\Users\...\RiderProjects\DataStructure\DataStructure\LinkedLists.cs:line 17
at Program.<Main>$(String[] args) in C:\Users\...\RiderProjects\DataStructure\DataStructure\Program.cs:line 109
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at DataStructure.LinkedLists`1.AddNode(T data) in C:\Users\...\RiderProjects\DataStructure\DataStructure\LinkedLists.cs:line 17
at Program.<Main>$(String[] args) in C:\Users\...\RiderProjects\DataStructure\DataStructure\Program.cs:line 109
Can someone explain how should I proceed to "decrypt" the stack trace error please. Should I read from top to bottom or bottom to top? How to interpret each line and which lines are the most important ones where it actually tells us the parent line which causes the error please
16 Replies
SG97
SG973w ago
LinkedLists.cs @ line 17 Topmost is the most recent
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
Faker
FakerOP3w ago
oh ok I see Thanks !
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
Faker
FakerOP3w ago
Noted, thanks ! Will keep that in mind 👍
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
Faker
FakerOP3w ago
yeah that's true, why is that, I mean normally we should recognised line 16 as being the one that throws the exception, right? This is because of the Release mode?
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
Faker
FakerOP3w ago
AH, so it doesn't know that the exception is line 16 because it's a new exception ?
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
Faker
FakerOP3w ago
Like if we would have use DivideByZeroException, it would have work ?
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
Faker
FakerOP3w ago
yeah I see, the easier way is to use the second method ? Like we just pass the exception object? and additional info we want to convey ?
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
Faker
FakerOP3w ago
Okep, will have a look at that later on then, thanks ! Really appreciate, just learnt new things 💯
Joschi
Joschi3w ago
Stack traces will often contain a lot of lines of MS library code. Because the exception happens down there. But you can often assume, that the actual error was produced in your code. So the first step is always to read and understand the actual error / exception. After that searching for the first mention of your own code in the stack trace is a good second step.

Did you find this page helpful?