Exceptions after compile to Release

S

Stanley

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

Code:
Imports System.Diagnostics
Public Class _default
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim a As Integer = 0
Dim b As Integer
Try
b = 1 \ a
Catch ex As Exception
Dim sf As New StackFrame(True)
Dim st As New StackTrace(sf)
Response.Write(ex.ToString.Replace(vbCrLf, "<br>"))
Response.Write("<br>")
Response.Write("Line #: " & st.GetFrame(0).ToString())
Response.Write("<br>")
Response.Write("Line #: " & st.GetFrame(0).GetFileLineNumber())
Response.Write("<br>")
Response.Write("Column #: " &
st.GetFrame(0).GetFileColumnNumber())
Response.Write("<br>")
Response.Write("Method : " & st.GetFrame(0).GetMethod().Name)
End Try


End Sub

End Class

[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]
 
S

Stanley

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


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

Code:
Imports System.Diagnostics
Public Class _default
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim a As Integer = 0
Dim b As Integer
Try
b = 1 \ a
Catch ex As Exception
Dim sf As New StackFrame(True)
Dim st As New StackTrace(sf)
Response.Write(ex.ToString.Replace(vbCrLf, "<br>"))
Response.Write("<br>")
Response.Write("Line #: " & st.GetFrame(0).ToString())
Response.Write("<br>")
Response.Write("Line #: " & st.GetFrame(0).GetFileLineNumber())
Response.Write("<br>")
Response.Write("Column #: " &
st.GetFrame(0).GetFileColumnNumber())
Response.Write("<br>")
Response.Write("Method : " & st.GetFrame(0).GetMethod().Name)
End Try


End Sub

End Class

[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]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top