Solved

How to show line number when an exception occures ?

Posted on 2011-02-24
6
954 Views
Last Modified: 2013-11-08
hi guys,
how can i assure that when an unhandled exception occurs in my code (the release version) the line number is shown in the error message ?
I know that i need to provide the pdb file to the target folder, but i have no clue what i need to do else  ? Can someone point me in the right direction ? I am using VB 2010.
0
Comment
Question by:Katzi
6 Comments
 
LVL 9

Expert Comment

by:rawinnlnx9
Comment Utility
Tools->Options->

Text Editor->All Languages->General put a check in "Line Numbers" and click ok.
0
 

Author Comment

by:Katzi
Comment Utility
hi , i did not mention how to show line numbers in the editor or not, what i want is that when the released version throws an unhandled exception the line number where the exception had been occured is showed in the error message.
0
 
LVL 2

Expert Comment

by:kambleamar
Comment Utility
Hello,

If you want to acces the function name and line number in Visuall Basic Net  [please reply if you  want in  VB6 we can try]

You have to do some R & D in StackFrame class

try bugging the code below once


protected string BuildMsg( string Msg,
Status.Stat MsgStatus,
Severity.Level SeverLevel,
short stackFrameLevel)
{
int nDebLocation = 0;
try
{
// Convert severity to 1 char
string strCurrSeverity = Severity.ToShortString(SeverLevel);

// Get stack information (FileName, Method, Line#)
StackFrame stFrame = new StackFrame(stackFrameLevel, true);

}

string strFileName;
if ( stFrame.GetFileName() != null)
strFileName =
stFrame.GetFileName().Substring(stFrame.GetFileNam e().LastIndexOf(@"\")+1);
else
strFileName = "Unknown???";


// Build information
string strFullInfo = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss.ff",
null) +
" [" + processInfo.MainModule.ModuleName + " - " +
strFileName + " - " + stFrame.GetMethod().Name +
"() - Line:" + (stFrame.GetFileLineNumber()).ToString() + "] " +
Environment.NewLine +
" [" + strCurrSeverity + ":" + ((int)MsgStatus).ToString("D5")
+ "] " + Msg + Environment.NewLine;


return strFullInfo;
}
catch (Exception ex)
{
return "Unable to build msg for logger. Err: " + ex.ToString() + ".
Dbg: " +
nDebLocation +
". Make sure the .PDB file has been copied in the Binary directory!";
}
}
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:Katzi
Comment Utility
hi Kambleamar, since i am not so familiar with C would you give me vb example ? That would be great.
Also, does this work in the release version too or just when using the debug version ?

thnaks in advance
0
 
LVL 41

Accepted Solution

by:
graye earned 50 total points
Comment Utility
Why not just recompile using the Debug (rather than Release)...   That way you don't have to do anything... the stack trace will automatically contain the line numbers.
0
 
LVL 2

Expert Comment

by:kambleamar
Comment Utility
Hello Katzi:

i have check out  it is not possible have line numbers  in VB6

you can get in  VB. net    

if you want to find the LIne number in the code

copy paste the  include  code  in the your error code and it will gice you the exact  line number
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now