Error Line Number In Vb.net
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How to use Stacktrace to return Error Line Number in vb.net up vote 5 down vote favorite 4 I am trying to create some sort of error catching method that will return the error line number. We have an abort email that is sent out when a process aborts that gives us the err.number and err.description but I would like to know where is actually errors out. I know you can do the following: 1: code here 2: code here 3: code here etc. and use ERL to get the number but it would be tedious to type each line out like that. Is there either a way to automatically do this or would it be easier to use Stacktrace? If Stacktrace is better could you please show me an example? vb.net error-handling stack-trace erl share|improve this question asked Nov 19 '12 at 19:23 user1836775 28113 1 ERL is the old way of doing things from VB6. Is there a reason not to use TRY/Catch? The exception object has a nice stack trace and includes the line number. –PatFromCanada Nov 19 '12 at 19:31 add a comment| 4 Answers 4 active oldest votes up vote 6 down vote accepted Generating line numbers in exception stack traces is a built-in feature for the CLR. You do however have to provide the information it needs to map a code address to a line number. Switch to the Release configuration of your project. Project + Properties, Compile tab, Advanced Compile Options. Change the "Generate debug info" setting from pdb-only to Full. Deploy the .pdb files along with your program. Beware that the line number you get is always an estimate so do not blindly trust what you see. The mapping is imperfect due to the jitter optimizer inlining methods and otherwise moving code ar
number If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. Results 1 to 4 of 4 Thread: [RESOLVED] How to get exact error line number Tweet Thread Tools Show Printable Version Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode Mar 31st, 2011,12:20 AM #1 medsont View Profile View Forum Posts Thread Starter Addicted Member Join Date Nov http://stackoverflow.com/questions/13460656/how-to-use-stacktrace-to-return-error-line-number-in-vb-net 2010 Location TamilNadu, India Posts 249 [RESOLVED] How to get exact error line number hi......... How can i get the exact error Line Number and Procedure/Function name Reply With Quote Mar 31st, 2011,12:34 AM #2 medsont View Profile View Forum Posts Thread Starter Addicted Member Join Date Nov 2010 Location TamilNadu, India Posts 249 Re: How to get exact error line number vb Code: Public Class Form1 Private Sub Button1_Click(ByVal sender http://www.vbforums.com/showthread.php?645850-RESOLVED-How-to-get-exact-error-line-number As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try Dim _intgr% = "error" Catch ex As Exception MsgBox(ex.ToString) MsgBox(ex.StackTrace) 'how can i get the error Line Number and Procedure Name and Class Name only.... End Try End SubEnd Class Reply With Quote Mar 31st, 2011,04:31 AM #3 TysonLPrice View Profile View Forum Posts PowerPoster Join Date Sep 2002 Location Columbus, Ohio Posts 2,650 Re: How to get exact error line number Same concept but closer to what you asked for: Code: Try 'Something Catch ex As Exception Dim trace = New System.Diagnostics.StackTrace(ex, True) MsgBox(ex.Message & vbCrLf & "Error in ClaimFlag10 - Line number:" & trace.GetFrame(0).GetFileLineNumber().ToString) End Try I'm probably wording this wrong but I think the .pdb file has to be available\installed for this to work properly. Reply With Quote Apr 1st, 2011,10:44 AM #4 medsont View Profile View Forum Posts Thread Starter Addicted Member Join Date Nov 2010 Location TamilNadu, India Posts 249 Re: How to get exact error line number Thank You mr TysonLPrice Reply With Quote Quick Navigation Visual Basic .NET Top Site Areas Settings Private Messages Subscriptions Who's
ASP.NET Community Standup Forums Help Home/ASP.NET Forums/General ASP.NET/Web Forms/VB.net: How to ALWAYS show the line number of the error VB.net: http://forums.asp.net/t/1816998.aspx?VB+net+How+to+ALWAYS+show+the+line+number+of+the+error How to ALWAYS show the line number of the error [Answered]RSS 2 replies Last post Jun 21, 2012 03:41 PM by Nasser Malik ‹ Previous Thread|Next Thread › Print Share Twitter Facebook Email Shortcuts Active Threads Unanswered Threads Unresolved Threads Support Options Advanced Search Related Links GuidanceSamplesVideos Reply tvb2727 Participant 891 Points 2376 Posts VB.net: error line How to ALWAYS show the line number of the error Jun 21, 2012 03:36 PM|tvb2727|LINK I am debugging a website I wrote. For some reason in my try/catch, it will show the error message, but no specific line # where the error occurred. How can I ALWAYS know the line # or what decides that? error line number This is a .vb file. VB.net code Catch ex As Exception logging.errors(ex.ToString, error_l) If HttpContext.Current.Session("where") = "cdrive" Then MsgBox(ex.ToString) End If Dim returnstring(0) As String returnstring(0) = False Return returnstring End Try Reply MattsDotNetU... Contributor 2151 Points 513 Posts Re: VB.net: How to ALWAYS show the line number of the error Jun 21, 2012 03:40 PM|MattsDotNetUsername|LINK You need to have the pdb file along with your DLL. Try running the website with those as well as your DLLsand you should see your line number. Reply Nasser Malik Star 12720 Points 2559 Posts Re: VB.net: How to ALWAYS show the line number of the error Jun 21, 2012 03:41 PM|Nasser Malik|LINK If you need the line number for more than just the formatted stack trace you get from Exception.StackTrace, you can use the StackTrace class: try { throw new Exception(); } catch (Exception ex) { // Get stack trace for the exception with source file information var st = new StackTrace(ex, true); // Ge