469,610 Members | 1,962 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,610 developers. It's quick & easy.

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 1745
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Robert Rotstein | last post: by
11 posts views Thread by Tamas Demjen | last post: by
1 post views Thread by Stanley | last post: by
reply views Thread by Jérôme Le Bougeant | last post: by
29 posts views Thread by mailforpr | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.