473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Exceptions after compile to Release

I am working with Exceptions and have found a bit of a problem for me.
Using the code below in Debug I get the info I want which is basically:
-Line of error
-Column of error
-Method where error happened

However, when you compile to Release version you get no line or column
numbers. So I assume this is because the .pdb file holds all of the info
regarding the lines and columns or something to that order. I am not
really to sure what the .pdb file actually holds.

So what I am after is a way to track down the exact place the error
happened without having to put a try...catch block everywhere in my
code. Am I going about this all wrong?

Also please note the code below is simply me playing and is in no way
complete or even ready for release. Also I should note that I am running
this by pressing F5 in VS.Net 2003 with DotNet Framework 1.1.

TIA
-Stanley

Expand|Select|Wrap|Line Numbers
  1. Imports System.Diagnostics
  2. Public Class _default
  3. Inherits System.Web.UI.Page
  4.  
  5. #Region " Web Form Designer Generated Code "
  6.  
  7. 'This call is required by the Web Form Designer.
  8. <System.Diagnostics.DebuggerStepThrough()> Private Sub
  9. InitializeComponent()
  10.  
  11. End Sub
  12.  
  13. 'NOTE: The following placeholder declaration is required by the Web
  14. Form Designer.
  15. 'Do not delete or move it.
  16. Private designerPlaceholderDeclaration As System.Object
  17.  
  18. Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
  19. System.EventArgs) Handles MyBase.Init
  20. 'CODEGEN: This method call is required by the Web Form Designer
  21. 'Do not modify it using the code editor.
  22. InitializeComponent()
  23. End Sub
  24.  
  25. #End Region
  26.  
  27. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
  28. System.EventArgs) Handles MyBase.Load
  29. Dim a As Integer = 0
  30. Dim b As Integer
  31. Try
  32. b = 1 \ a
  33. Catch ex As Exception
  34. Dim sf As New StackFrame(True)
  35. Dim st As New StackTrace(sf)
  36. Response.Write(ex.ToString.Replace(vbCrLf, "<br>"))
  37. Response.Write("<br>")
  38. Response.Write("Line #: " & st.GetFrame(0).ToString())
  39. Response.Write("<br>")
  40. Response.Write("Line #: " & st.GetFrame(0).GetFileLineNumber())
  41. Response.Write("<br>")
  42. Response.Write("Column #: " &
  43. st.GetFrame(0).GetFileColumnNumber())
  44. Response.Write("<br>")
  45. Response.Write("Method : " & st.GetFrame(0).GetMethod().Name)
  46. End Try
  47.  
  48.  
  49. End Sub
  50.  
  51. End Class
  52.  
[debug results]
System.DivideByZeroException: Attempted to divide by zero.
at pcTracker._default.Page_Load(Object sender, EventArgs e) in
C:\Inetpub\wwwroot\pcTracker\default.aspx.vb:line 28
Line #: Page_Load at offset 131 in file:line:column
C:\Inetpub\wwwroot\pcTracker\default.aspx.vb:30:17
Line #: 30
Column #: 17
Method : Page_Load
[/debug results]

[release results]
System.DivideByZeroException: Attempted to divide by zero.
at pcTracker._default.Page_Load(Object sender, EventArgs e)
Line #: Page_Load at offset 128 in file:line:column :0:0
Line #: 0
Column #: 0
Method : Page_Load

[/release results]
Jul 21 '05 #1
1 1874
Well after some research I have found that what I want to do is not
actually possible. I guess I can live with the method that the error is
in using the "GetMethod" method, but what about the page? Below is what
I have come up with as a guide to what can be used as far as the methods
of the StackFrame. Hope it saves someone the trouble I went through.

-Stanley

Equals (inherited from Object) - Debug and Release
GetFileColumnNumber - Debug Only
GetFileLineNumber - Debug Only
GetFileName - Debug Only
GetHashCode - Debug and Release
GetILOffset - ???
GetMethod - Debug and Release
GetNativeOffset - ???
GetType - Debug and Release
ToString - Debug and Release

Stanley wrote:
I am working with Exceptions and have found a bit of a problem for me.
Using the code below in Debug I get the info I want which is basically:
-Line of error
-Column of error
-Method where error happened

However, when you compile to Release version you get no line or column
numbers. So I assume this is because the .pdb file holds all of the info
regarding the lines and columns or something to that order. I am not
really to sure what the .pdb file actually holds.

So what I am after is a way to track down the exact place the error
happened without having to put a try...catch block everywhere in my
code. Am I going about this all wrong?

Also please note the code below is simply me playing and is in no way
complete or even ready for release. Also I should note that I am running
this by pressing F5 in VS.Net 2003 with DotNet Framework 1.1.

TIA
-Stanley

Expand|Select|Wrap|Line Numbers
  1.  Imports System.Diagnostics
  2.  Public Class _default
  3.      Inherits System.Web.UI.Page
  4.  #Region " Web Form Designer Generated Code "
  5.      'This call is required by the Web Form Designer.
  6.      <System.Diagnostics.DebuggerStepThrough()> Private Sub
  7.  InitializeComponent()
  8.      End Sub
  9.      'NOTE: The following placeholder declaration is required by the Web
  10.  Form Designer.
  11.      'Do not delete or move it.
  12.      Private designerPlaceholderDeclaration As System.Object
  13.      Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
  14.  System.EventArgs) Handles MyBase.Init
  15.          'CODEGEN: This method call is required by the Web Form Designer
  16.          'Do not modify it using the code editor.
  17.          InitializeComponent()
  18.      End Sub
  19.  #End Region
  20.      Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
  21.  System.EventArgs) Handles MyBase.Load
  22.          Dim a As Integer = 0
  23.          Dim b As Integer
  24.          Try
  25.              b = 1 \ a
  26.          Catch ex As Exception
  27.              Dim sf As New StackFrame(True)
  28.              Dim st As New StackTrace(sf)
  29.              Response.Write(ex.ToString.Replace(vbCrLf, "<br>"))
  30.              Response.Write("<br>")
  31.              Response.Write("Line #: " & st.GetFrame(0).ToString())
  32.              Response.Write("<br>")
  33.              Response.Write("Line #: " & st.GetFrame(0).GetFileLineNumber())
  34.              Response.Write("<br>")
  35.              Response.Write("Column #: " &
  36.  st.GetFrame(0).GetFileColumnNumber())
  37.              Response.Write("<br>")
  38.              Response.Write("Method : " & st.GetFrame(0).GetMethod().Name)
  39.          End Try
  40.      End Sub
  41.  End Class
  42.  

[debug results]
System.DivideByZeroException: Attempted to divide by zero.
at pcTracker._default.Page_Load(Object sender, EventArgs e) in
C:\Inetpub\wwwroot\pcTracker\default.aspx.vb:line 28
Line #: Page_Load at offset 131 in file:line:column
C:\Inetpub\wwwroot\pcTracker\default.aspx.vb:30:17
Line #: 30
Column #: 17
Method : Page_Load
[/debug results]

[release results]
System.DivideByZeroException: Attempted to divide by zero.
at pcTracker._default.Page_Load(Object sender, EventArgs e)
Line #: Page_Load at offset 128 in file:line:column :0:0
Line #: 0
Column #: 0
Method : Page_Load

[/release results]

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Robert Rotstein | last post by:
It appears that exception handling at the top-most level of a C# program, in the static void Main() method, differs depending on whether the program is run in debug mode or not. That is, code such...
12
by: Vasco Lohrenscheit | last post by:
Hi, I have a Problem with unmanaged exception. In the debug build it works fine to catch unmanaged c++ exceptions from other dlls with //managed code: try { //the form loads unmanaged dlls...
11
by: Tamas Demjen | last post by:
I was shocked to learn that VC++ 2005 Beta 2 can't catch Access Violation exceptions in unmanaged code. To reproduce this, I created a minimal Win32 console application: #include "stdafx.h" ...
1
by: Stanley | last post by:
I am working with Exceptions and have found a bit of a problem for me. Using the code below in Debug I get the info I want which is basically: -Line of error -Column of error -Method where error...
0
by: Jérôme Le Bougeant | last post by:
Hello (and sorry for my English), I downloaded the VideoCapture module on the http://videocapture.sourceforge.net/ site. I tested it with a webcam and that functions. Now I want to...
29
by: mailforpr | last post by:
Sometimes, I can't think of any good reason why I should have the program's logic thrown an exception. Except for catching the exception and printing "Uh, oh" to the screen. I also think that in...
6
by: robert | last post by:
I get python crashes and (in better cases) strange Python exceptions when (in most cases) importing and using cookielib lazy on demand in a thread. It is mainly with cookielib, but remember the...
1
by: Daniel | last post by:
do release builds have the same amount of info in exceptions? e.g. will exceptions cought in release builds contain stack trace etc.?
22
by: ben mitch | last post by:
Hi I hope you'll see this cross-post (c/c++) as appropriate. I also admit immediately that the question *may* turn out to be compiler-/os-specific, in which case I apologize. But I wonder if...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.