locked
Not responding to thrown error RRS feed

  • Question

  • User646364117 posted

    problem is when I break at If ex IsNot Nothing Then

    ex is Nothing

    Please advise

    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
    
    
    
                Dim ex As Exception = Server.GetLastError()
    
                If ex IsNot Nothing Then
                    Logger.Log(ex)
                    Server.ClearError()
                    Server.Transfer("~/Errors.aspx")
                End If
            End Try
        End Sub
    Public Class DuplicateTemplateException : Inherits ApplicationException
        Public Sub New(ByVal text As String)
            MyBase.New(text)
        End Sub
    End Class

    Wednesday, March 18, 2020 2:12 PM

Answers

  • User475983607 posted

    Please use Try...Catch standard conventions found in the official VB.NET reference documentation.

    https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/try-catch-finally-statement

    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
    			Logger.Log(ex)
    			Server.ClearError()
    			Server.Transfer("~/Errors.aspx")
    		End If
    	End Try
    End Sub

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 18, 2020 2:27 PM