Solved

How to show line number when an exception occures ?

Posted on 2011-02-24
6
969 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 9

Expert Comment

by:rawinnlnx9
ID: 34973238
Tools->Options->

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

Author Comment

by:Katzi
ID: 34973307
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
ID: 34977331
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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 

Author Comment

by:Katzi
ID: 34991154
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
ID: 34998491
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
ID: 35004364
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

734 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