Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Equivalent of VFP's LineNo() and Program() ?
Message
From
24/05/2005 11:48:26
 
 
To
24/05/2005 08:06:01
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 1.1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01017003
Message ID:
01017108
Views:
27
Hey Alex,

The StackTrace is useful, but I don't think you've used it correctly. Try the StackTrace property of the Exception that got thrown. IOW, something like this:
catch (Exception ex)
{
	MessageBox.Show(ex.Message + (char)13 + 
			ex.StackTrace.ToString());
}
In debug mode it will give you the correct line number.

~~Bonnie




>>I wrote an ErrorLog class, based on ideas from Kevin McNeish's book. It allows for logging of errors, exceptions and straight messages to an XML log.
>>
>>I can send a flag to optionally include Exception.StackTrace which I normally turn off as it is too verbose.
>>
>>One thing I'm looking for, if it exists is the equivalent of VFP's LineNo() and Program() to add to the message I create. These I'd need for a straight message, not based on an Exception class.
>>
>>Is here such an animal in .Net (C#)?

>
>
>I searched the help files and found System.Diagnostics:
>
>StackTrace st = new StackTrace(true);
>StackFrame sf = st.GetFrame(0);
>Console.WriteLine("Method: {0}",sf.GetMethod());
>Console.WriteLine("Line Number: {0}",sf.GetFileLineNumber());
>
>but this code always returns line 0 in a release (production) console exe
>
>If I run it in the debugger, it returns the line number of the StackTrace creation line above.
>So it looks like the release version does not include debug info/source code line numbers (at least I don't yet know how), and the debugger does not return the real line number (I have line numbers turned on in the editor).
>
>In some ways VFP is nicer and easier isn't it? <g>
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform