Solved

How to show line number when an exception occures ?

Posted on 2011-02-24
6
956 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
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

932 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

12 Experts available now in Live!

Get 1:1 Help Now