Link to home
Start Free TrialLog in
Avatar of nphoenix
nphoenix

asked on

Global error handling - customErrors mode="RemoteOnly" defaultRedirect="errorhandler.aspx"

Can i set <customErrors mode="RemoteOnly" defaultRedirect="errorhandler.aspx"> in my web.config, and then in ="errorhandler.aspx" i want to email my self the error. But even loading alabel control with the error that took me to the page (errorhandler.aspx) is causing me an issue.

Can i do something like
Imports System.Diagnostics
Dim ex As Exception = Server.GetLastError().GetBaseException()
label1.text = ex.message ???


This gives me - Object reference not set to an instance of an object.

Avatar of thecodist
thecodist
Flag of United States of America image

What happens if you do something like:

Dim ex As New Exception(Server.GetLastError().GetBaseException().Message)
Avatar of nphoenix
nphoenix

ASKER

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
but i am running the page (with no error present) as a test directly... is that why its null?
no - still an error when i access an intentionally broken page - and it rolls to errorhandler.aspx
How about if you try:

Dim ex As Exception
If Not Server.GetLastError() Is Nothing Then
    ex = Server.GetLastError().GetBaseException()
        (OR)
    ex = New Exception(Server.GetLastError().GetBaseException().Message)
End If
Does the old error object show anything?
Dim ex As Exception
On Error Resume Next

'Error Condition

If Err.Number <> 0 Then
    'Does Err object show anything?
    Dim ErrorDescription As String = Err.Description
    On Error GoTo 0
    Err.Clear
    ex = New Exception(ErrorDescription)
End If
ASKER CERTIFIED SOLUTION
Avatar of patilmmilind
patilmmilind

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Could you share the SQL code as well?

Thanks very much
Anthony.