HighTechTalks DotNet Forums  

Exception and StackTrace .... more info ?? HOW?

Dotnet General Discussions microsoft.public.dotnet.general


Discuss Exception and StackTrace .... more info ?? HOW? in the Dotnet General Discussions forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Kristijan Marin
 
Posts: n/a

Default Exception and StackTrace .... more info ?? HOW? - 12-28-2007 , 01:39 PM






Hi,

Can please anyone tell me why do i get only the first method in which the
exception was thrown and not the line that triggered the exception ? I don't
know if I set something in VS2005 wrong or what the hell is wrong ....

I have a Windows Service in RELEASE mode , on VS2005 C# .....

So to summarize ... when the exception is thrown, I catch it and display the
stacktrace of the exception, but as I said above, only the calling method is
showen..... the exception is thrown in QueueService.queueTimer_Elapsed
method .....


Thanks a lot.
Kris

Example :

<here I would expect to see the line of exception or at least the name of
the method ....>
at ReportQueueService.QueueService.queueTimer_Elapsed (Object sender,
ElapsedEventArgs e)
at System.Timers.Timer.MyTimerCallback(Object state)
at System.Threading._TimerCallback.TimerCallback_Cont ext(Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading._TimerCallback.PerformTimerCallba ck(Object state)



Reply With Quote
  #2  
Old   
Peter Ritchie [C# MVP]
 
Posts: n/a

Default RE: Exception and StackTrace .... more info ?? HOW? - 12-29-2007 , 12:24 AM






CallStacks don't have line numbers in them, only the method names.

When running code the runtime runs IL, not C#--so line numbers are
meaningless at that point.

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#


"Kristijan Marin" wrote:

Quote:
Hi,

Can please anyone tell me why do i get only the first method in which the
exception was thrown and not the line that triggered the exception ? I don't
know if I set something in VS2005 wrong or what the hell is wrong ....

I have a Windows Service in RELEASE mode , on VS2005 C# .....

So to summarize ... when the exception is thrown, I catch it and display the
stacktrace of the exception, but as I said above, only the calling method is
showen..... the exception is thrown in QueueService.queueTimer_Elapsed
method .....


Thanks a lot.
Kris

Example :

here I would expect to see the line of exception or at least the name of
the method ....
at ReportQueueService.QueueService.queueTimer_Elapsed (Object sender,
ElapsedEventArgs e)
at System.Timers.Timer.MyTimerCallback(Object state)
at System.Threading._TimerCallback.TimerCallback_Cont ext(Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading._TimerCallback.PerformTimerCallba ck(Object state)




Reply With Quote
  #3  
Old   
Kristijan Marin
 
Posts: n/a

Default Re: Exception and StackTrace .... more info ?? HOW? - 12-30-2007 , 01:32 PM



Hi,

I understand, but as I said, I would expect a little more form StackTrace
then just the Parant method .... cause if i have a method with 100 lines,
and exception occures in some iostream like "ReadLine" then I would expect
to see that Exception occured in "ReadLine" method

For instance:

public void MyMethod()
{
int i;
try
{
..
..
..
..
o.ReadLine(); ///exception here
..
..
..
}catch(Exception e)
{
WRITE STACK

}
}




..... I don't know if this was ever in C# like there is trace in JAVA where
you see exactly where it happened or not, but I think this was showen when I
was doing Desktop application ...

Thx.
Kris

"Peter Ritchie [C# MVP]" <PRSoCo (AT) newsgroups (DOT) nospam> wrote

Quote:
CallStacks don't have line numbers in them, only the method names.

When running code the runtime runs IL, not C#--so line numbers are
meaningless at that point.

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#


"Kristijan Marin" wrote:

Hi,

Can please anyone tell me why do i get only the first method in which the
exception was thrown and not the line that triggered the exception ? I
don't
know if I set something in VS2005 wrong or what the hell is wrong ....

I have a Windows Service in RELEASE mode , on VS2005 C# .....

So to summarize ... when the exception is thrown, I catch it and display
the
stacktrace of the exception, but as I said above, only the calling method
is
showen..... the exception is thrown in QueueService.queueTimer_Elapsed
method .....


Thanks a lot.
Kris

Example :

here I would expect to see the line of exception or at least the name
of
the method ....
at ReportQueueService.QueueService.queueTimer_Elapsed (Object sender,
ElapsedEventArgs e)
at System.Timers.Timer.MyTimerCallback(Object state)
at System.Threading._TimerCallback.TimerCallback_Cont ext(Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading._TimerCallback.PerformTimerCallba ck(Object state)






Reply With Quote
  #4  
Old   
Jon Skeet [C# MVP]
 
Posts: n/a

Default Re: Exception and StackTrace .... more info ?? HOW? - 12-30-2007 , 02:23 PM



Kristijan Marin <kristijan.marin (AT) triera (DOT) net> wrote:
Quote:
I understand, but as I said, I would expect a little more form StackTrace
then just the Parant method .... cause if i have a method with 100 lines,
and exception occures in some iostream like "ReadLine" then I would expect
to see that Exception occured in "ReadLine" method
And unless inlining has occurred, this will usually be the case.

However, without a short but complete program demonstrating the
problem, it's hard to say why you're not seeing the behaviour you
expect.

--
Jon Skeet - <skeet (AT) pobox (DOT) com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk


Reply With Quote
  #5  
Old   
Kristijan Marin
 
Posts: n/a

Default Re: Exception and StackTrace .... more info ?? HOW? - 12-30-2007 , 07:36 PM



Hi,

Ok now we understand each other ..... ....

So please tell me, could it be possible that I somewhere turned some VS or
Project property off or on and this
now gives the "not expected" stack result ?

I doubt that program example would somehow help, cause this is happening to
all Window Service
applications that i have so I think that it could be some VS setting
problem .... but don't know which ....

Thanks.
Kris

"Jon Skeet [C# MVP]" <skeet (AT) pobox (DOT) com> wrote

Quote:
Kristijan Marin <kristijan.marin (AT) triera (DOT) net> wrote:
I understand, but as I said, I would expect a little more form StackTrace
then just the Parant method .... cause if i have a method with 100
lines,
and exception occures in some iostream like "ReadLine" then I would
expect
to see that Exception occured in "ReadLine" method

And unless inlining has occurred, this will usually be the case.

However, without a short but complete program demonstrating the
problem, it's hard to say why you're not seeing the behaviour you
expect.

--
Jon Skeet - <skeet (AT) pobox (DOT) com
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk



Reply With Quote
  #6  
Old   
Jon Skeet [C# MVP]
 
Posts: n/a

Default Re: Exception and StackTrace .... more info ?? HOW? - 12-30-2007 , 07:41 PM



Kristijan Marin <kristijan.marin (AT) triera (DOT) net> wrote:
Quote:
Ok now we understand each other ..... ....

So please tell me, could it be possible that I somewhere turned some VS or
Project property off or on and this
now gives the "not expected" stack result ?
No, not really.

You *could* be rethrowing an exception using:

throw e;

instead of

throw;

Quote:
I doubt that program example would somehow help, cause this is happening to
all Window Service
applications that i have so I think that it could be some VS setting
problem .... but don't know which ....
No, it won't be a VS setting. Try the following complete program, in
Debug mode (to avoid inlining).

using System;

class Test
{
static void Main()
{
try
{
Outer();
}
catch (Exception e)
{
Console.WriteLine (e);
}
}

static void Outer()
{
Inner();
}

static void Inner()
{
ThrowException();
}

static void ThrowException()
{
throw new Exception("Ouch!");
}
}

You should get a stack trace like this:

System.Exception: Ouch!
at Test.ThrowException() in c:\Users\Jon\Test\Test.cs:line 29
at Test.Inner() in c:\Users\Jon\Test\Test.cs:line 24
at Test.Outer() in c:\Users\Jon\Test\Test.cs:line 19
at Test.Main() in c:\Users\Jon\Test\Test.cs:line 9

--
Jon Skeet - <skeet (AT) pobox (DOT) com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk


Reply With Quote
  #7  
Old   
Adam Benson
 
Posts: n/a

Default Re: Exception and StackTrace .... more info ?? HOW? - 01-02-2008 , 07:04 AM



Does this help ?



public static string StackTraceToString(System.Diagnostics.StackTrace trace)

{

StackFrame sf;

System.Text.StringBuilder s = new System.Text.StringBuilder();

for (int i = 0; i < trace.FrameCount; i++)

{

sf = trace.GetFrame(i);

s = s.AppendFormat(" {0} in {1} (Line {2}, Column {3}){4}",

sf.GetMethod(),

sf.GetFileName(),

sf.GetFileLineNumber(),

sf.GetFileColumnNumber(),

Environment.NewLine );

}

return s.ToString();

}



What happens if you try a debug build rather than a release build?



Cheers,



Adam.

=======


"Kristijan Marin" <kristijan.marin (AT) triera (DOT) net> wrote

Quote:
Hi,

Can please anyone tell me why do i get only the first method in which the
exception was thrown and not the line that triggered the exception ?



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.