Tracing inside method

P

Peter Duniho

Ganze said:
I work with try/catch block. Since its a multy line method I would like to
know excatly what is the last command that passes succefully before going to
the catch block.

Define "command". Do you mean a program statement? An individual
operation or expression evaluation? Something else?
Is there some way to do it without embeding logger messages after every code
line?

Sure. But any solution will involve _something_ like that, such as
setting flags, keeping a counter, etc. There's nothing built in that
would tell you the last successful program statement.

However, note that you can get almost all the way there just by
inspecting the StackTrace in the exception object.

Because a single statement can include multiple operations and even
multiple method calls, and of course because an exception that occurs
inside a method call involves other code that has successfully executed
besides that which is found in your try/catch block, the StackTrace does
not give you a precise, per-operation information. But it will give you
the information down to the program statement, which may be enough for
your needs, depending on what exactly you actually mean by "command".

Pete
 
G

Ganze

I work with try/catch block. Since its a multy line method I would like to
know excatly what is the last command that passes succefully before going to
the catch block.
Is there some way to do it without embeding logger messages after every code
line?
Regards
Ganze
 
G

Ganze

Thanks Pete,
though my question was not clear enouph you really directed me to what I
need..
Regards
You are greate...
Ganze
 
A

Arne Vajhøj

I work with try/catch block. Since its a multy line method I would like to
know excatly what is the last command that passes succefully before going to
the catch block.
Is there some way to do it without embeding logger messages after every code
line?

Not really.

Because you need to realize that after optimization by the
JIT compiler then the question does not make any sense any
more.

Let us say that:
line 1 -> instructions A, B and C
line 2 -> instructions D, E and F
line 3 -> instructions G, H and I

The after optimization the instructions are
executed in the order:
A D G B E H C F I

And then the exception happens at B.

What line number do you want?

Arne
 
P

Peter Duniho

Ganze said:
Thanks Arne,
Is ther a way to eliminate JIT optimization?

The "Debug" build configuration disables optimizations at both the
C#-to-IL and IL-to-native (i.e. JIT) phases.

IMHO, your question makes as much sense as asking whether the debugger
can step through your code reliably. Which is to say, it's a fine
question…you just have to be aware of the scenarios where it won't work
as well.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top