tags:

views:

70

answers:

2

Hi,

In an aspx web page I'm doing this:

Try

    Throw new IndexOutOfRangeException

Catch ex As Exception

    Dim myException As New bizException(ex)

    Throw myException

End Try

In the global.asax I'm doing this:

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)

    Dim myException As bizException = DirectCast(Server.GetLastError().GetBaseException(), bizException)


End Sub

An this error is occuring during the cast:

InvalidCastException: Unable to cast object of type 'System.IndexOutOfRangeException' to type 'bizException'.

The GetLastError's type is IndexOutOfRangeException and not bizException... Why ?

A: 

Try this instead:

Dim myException As bizException = DirectCast(Server.GetLastError(), bizException)

(Removed "GetBaseException" call.)

daughtkom
daughtkom:I got a different error message: Unable to cast object of type 'System.Web.HttpUnhandledException' to type 'bizException'.
David
A: 

daughtkom:

I got a different error message:

Unable to cast object of type 'System.Web.HttpUnhandledException' to type 'bizException'.
David