Link to home
Start Free TrialLog in
Avatar of Katzi
KatziFlag for Germany

asked on

How to show line number when an exception occures ?

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.
Avatar of rawinnlnx9
rawinnlnx9
Flag of United States of America image

Tools->Options->

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

ASKER

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.
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!";
}
}
Avatar of Katzi

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of graye
graye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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