Exception and StackTrace .... more info ?? HOW?
Exception and StackTrace .... more info ?? HOW?
am 28.12.2007 19:39:10 von Kristijan Marin
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 :
the method ....>
at ReportQueueService.QueueService.queueTimer_Elapsed(Object sender,
ElapsedEventArgs e)
at System.Timers.Timer.MyTimerCallback(Object state)
at System.Threading._TimerCallback.TimerCallback_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading._TimerCallback.PerformTimerCallback(Object state)
RE: Exception and StackTrace .... more info ?? HOW?
am 29.12.2007 06:24:00 von PRSoCo
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 :
>
>
> the method ....>
> at ReportQueueService.QueueService.queueTimer_Elapsed(Object sender,
> ElapsedEventArgs e)
> at System.Timers.Timer.MyTimerCallback(Object state)
> at System.Threading._TimerCallback.TimerCallback_Context(Object state)
> at System.Threading.ExecutionContext.Run(ExecutionContext
> executionContext, ContextCallback callback, Object state)
> at System.Threading._TimerCallback.PerformTimerCallback(Object state)
>
>
>
Re: Exception and StackTrace .... more info ?? HOW?
am 30.12.2007 19:32:53 von Kristijan Marin
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]" wrote in message
news:D59F1EF2-7414-4FE6-B404-DB76DF29389F@microsoft.com...
> 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 :
>>
>>
>> of
>> the method ....>
>> at ReportQueueService.QueueService.queueTimer_Elapsed(Object sender,
>> ElapsedEventArgs e)
>> at System.Timers.Timer.MyTimerCallback(Object state)
>> at System.Threading._TimerCallback.TimerCallback_Context(Object state)
>> at System.Threading.ExecutionContext.Run(ExecutionContext
>> executionContext, ContextCallback callback, Object state)
>> at System.Threading._TimerCallback.PerformTimerCallback(Object state)
>>
>>
>>
Re: Exception and StackTrace .... more info ?? HOW?
am 30.12.2007 20:23:13 von skeet
Kristijan Marin 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 -
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Re: Exception and StackTrace .... more info ?? HOW?
am 31.12.2007 01:36:09 von Kristijan Marin
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]" wrote in message
news:MPG.21e2007fe16621d775f@msnews.microsoft.com...
> Kristijan Marin 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 -
> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
> World class .NET training in the UK: http://iterativetraining.co.uk
Re: Exception and StackTrace .... more info ?? HOW?
am 31.12.2007 01:41:40 von skeet
Kristijan Marin wrote:
> 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;
> 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 -
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Re: Exception and StackTrace .... more info ?? HOW?
am 02.01.2008 13:04:30 von Adam Benson
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" wrote in message
news:%239IhxDYSIHA.2268@TK2MSFTNGP02.phx.gbl...
> 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 ?