This question already has answers here:
What do the "+n" values mean at the end of a method name in a stack trace?
(4 answers)
Closed 9 years ago.
I am trying to track down an exception thrown in a c# web app I have created and was wondering if someome could tell me what the + numbers relate to on each line in the stack trace
It's the offset from the start of the method, so the Exception is thrown 110 bytes (in IL) from the start of GetEmployee (which is not directly translatable to a line number due to compiling, jitting, inlining etc.)
Related
This question already has answers here:
What happens if an exception occurs in Catch block in C#. Also what would be the caller result in that case
(7 answers)
What happens if a finally block throws an exception?
(11 answers)
Closed 2 years ago.
When managed code is being executed by a .Net CLR, what happens if a second exception is thrown whilst the runtime is unwinding the stack due to an initial exception?
This doesn't refer to rethrowing an exception from a Catch block. It covers situations where an exception is thrown whilst the CLR is in the process of unwinding the stack.
In C++, this would cause the program to terminate, but I can't find any documentation about the behaviour in .Net.
This question already has answers here:
How do I get the current line number?
(7 answers)
Closed 2 years ago.
c language has macro like FILE/LINE to print file name and code line number
So how does C# language achieve same goal, is it possible to do, or require assembly packages?
Thanks a lot.
You can use StackFrame, i would be wary about doing this though, it will come at a performance cost and is likely to give you issues in release .
Represents a stack trace, which is an ordered collection of one or
more stack frames.
var stackTrace = new StackTrace(0, true);
var sf = stackTrace.GetFrame(0);
Console.WriteLine("FileName: {0}", sf.GetFileName());
Console.WriteLine("Line Number:{0} ",sf.GetFileLineNumber());
Console.WriteLine("Function Name:{0}",sf.GetMethod ());
This question already has answers here:
How to print the current Stack Trace in .NET without any exception?
(7 answers)
Closed 3 years ago.
Short version: Is there a way to somehow save the current call stack and store it for later?
Context: This issue seems like it would be so common that I might just be missing the correct search terms.
A certain class needs to read a variable from a server. I just send the request to the server using an API and at some point in the future a separate thread will get the reply and call some follow up method on the original caller class.
Simple enough, but there might be errors: either the variable I'm trying to get doesn't exist, is an incorrect type or something else. In those cases the best I can output to a debug log can be something like: "Unable to find variable X" and a stack trace of the worker. What I would really like having is a stack trace of the original caller, that I can store somewhere and print out in case there is an error so I can narrow down issues instead of having to hunt down which caller it is.
Environment.StackTrace would give you the current stack trace.
This question already has answers here:
How can I determine which exceptions can be thrown by a given method?
(9 answers)
Finding out what exceptions a method might throw in C#
(4 answers)
Closed 9 years ago.
Very simple really - is there a way to check and make a list of all exceptions that a method might throw? I have used try/catch but I want to make sure I didn't miss anything, and going through big files line by line to check if that line is throwing something that might be uncaught on runtime is a pain...
Oh yeah, I am using C#, .NET 4.5 and VS2012 PRO.
Thanks good people.
In C#, all objects that are thrown must derive from System.Exception. If you catch System.Exception, you catch them all, no matter what subtype.
This question already has answers here:
Is there a way to log or intercept First Chance Exceptions
(3 answers)
Closed 5 years ago.
Is there a way to catch First-Chance exceptions, and log them without running under a debugger?
I suppose another way to ask the question is can I write something that will act like a debugger being attached to my process and see what is going wrong while it happens?
If you are on .NET 4.0, you can use theAppDomain.FirstChanceExceptionevent to get notification of exceptions.