User646364117 posted
I am transferring to a custom error page.
When I GetLastError it is Nothing so getting null exception error
I have a different version where I use Session variables for the ex message and stack trace and I can consume these on the error page.
Why doesn't this method work?
This is code behind of error page
Imports System.Configuration
Imports System.Text
Imports System.Diagnostics
Partial Class Errors
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim ex As Exception
ex = Server.GetLastError '<< Get null reference error here
Server.ClearError()
End If
End Sub
End Class
This is code behind of page where error is thrown
Protected Sub BindGvCategoryTemplate()
Try
Throw New DuplicateTemplateException("Exception Occured in GetCategoryTemplateDataTable - Line 115")
Dim dtCategoryTemplate As DataTable
dtCategoryTemplate = GetCategoryTemplateDataTable()
gvCategoryTemplate.DataSource = dtCategoryTemplate
gvCategoryTemplate.DataBind()
Exit Sub
Catch ex As Exception
If ex IsNot Nothing Then
Server.Transfer("~/Errors.aspx")
End If
End Try
End Sub