Prev: MEF with VS2008
Next: using new List<String>();
From: Ganze on 26 May 2010 05:26 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
From: Peter Duniho on 26 May 2010 04:59 Ganze wrote: > 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
From: Ganze on 26 May 2010 17:02 Thanks Pete, though my question was not clear enouph you really directed me to what I need.. Regards You are greate... Ganze "Peter Duniho" <no.peted.spam(a)no.nwlink.spam.com> wrote in message news:O3YM$GL$KHA.3840(a)TK2MSFTNGP02.phx.gbl... > Ganze wrote: >> 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
From: Arne Vajhøj on 26 May 2010 22:18 On 26-05-2010 05:26, Ganze wrote: > 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
From: Ganze on 27 May 2010 08:03
Thanks Arne, Is ther a way to eliminate JIT optimization? Regards Ganze "Arne Vajh�j" <arne(a)vajhoej.dk> wrote in message news:4bfdd67d$0$276$14726298(a)news.sunsite.dk... > On 26-05-2010 05:26, Ganze wrote: >> 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 > |