I have custom error handling configured for my application. In web.config I have:
<customErrors defaultRedirect="ErrorDisplay.aspx" mode="On">
<error statusCode="404" redirect="Error404.htm"/>
</customErrors>
This works very well, except in Global.asax. The following code throws an error in the data layer, which rethrows the error and gets caught in the try block below. I then throw my error (a custom class derived from the ssytem exception type). When I do this in any other page, it redirects to my custom error page as expected. However, in the App_Start of global.asax, it does not and the app goes on to display the first page of the site, not the error page. Is there a reason for this, am I doing something wrong? Thanks.
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application is started
Dim dsPriority As DataSet, oNetData As MSIData, dbCon As SqlClient.SqlConnection
Try
strDefConString = System.Configuration.ConfigurationSettings.AppSett ings("ConnectionString")
oNetData = New MSIData
dbCon = oNetData.GetConnection(strDefConString)
Application("PriorityListDS") = oNetData.SProcDataSet(dbCon, "GetPriorityList")
Catch ex As Exception
Dim excNew As MSIException = New MSIException("An error occured during application start." + ControlChars.NewLine + ex.Message)
excNew.TrueSource = "Application_Start"
Throw excNew
End Try
End Sub