Katzi
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.
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.
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(Sev erLevel);
// Get stack information (FileName, Method, Line#)
StackFrame stFrame = new StackFrame(stackFrameLevel , true);
}
string strFileName;
if ( stFrame.GetFileName() != null)
strFileName =
stFrame.GetFileName().Subs tring(stFr ame.GetFil eNam e().LastIndexOf(@"\")+1);
else
strFileName = "Unknown???";
// Build information
string strFullInfo = DateTime.Now.ToString("dd/ MM/yyyy HH:mm:ss.ff",
null) +
" [" + processInfo.MainModule.Mod uleName + " - " +
strFileName + " - " + stFrame.GetMethod().Name +
"() - Line:" + (stFrame.GetFileLineNumber ()).ToStri ng() + "] " +
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!";
}
}
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(Sev
// Get stack information (FileName, Method, Line#)
StackFrame stFrame = new StackFrame(stackFrameLevel
}
string strFileName;
if ( stFrame.GetFileName() != null)
strFileName =
stFrame.GetFileName().Subs
else
strFileName = "Unknown???";
// Build information
string strFullInfo = DateTime.Now.ToString("dd/
null) +
" [" + processInfo.MainModule.Mod
strFileName + " - " + stFrame.GetMethod().Name +
"() - Line:" + (stFrame.GetFileLineNumber
Environment.NewLine +
" [" + strCurrSeverity + ":" + ((int)MsgStatus).ToString(
+ "] " + 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!";
}
}
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
Also, does this work in the release version too or just when using the debug version ?
thnaks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
Text Editor->All Languages->General put a check in "Line Numbers" and click ok.