locked
RE: Custom Exceptions in ASP.Net 3.5 Web Form RRS feed

  • Question

  • User-197737650 posted

    Hi all,

    Have a Web Form that deals with data. Want to throw a custom exception class that I want to live in the App_Code folder(or anywhere I can write it once and not have to copy/paste for each page that uses it)

    The code will work in an individual page as an inline class, but will not recognize class even when I import it, even though I shouldn't have to. Coming at this from a Java perspective, so I think I'm missing something obvious to ASP.Net vets

      Class code from App_Code folder:

    Public Class UpdateException
        Inherits System.Exception
        Private e As String
        Public Sub New()

        End Sub
        Public Sub New(ByVal message As String)
            MyBase.New(message)
            e = message
        End Sub
        Public Sub New(ByRef message As String, ByVal inner As Exception)
            MyBase.New(message, inner)
            If e = "" Then
                e = message

            End If
        End Sub
        Public Sub New(ByVal info As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext)
            MyBase.New(info, context)
            If e = "" Then
                e = Message
            End If
        End Sub

        Public Function emessage() As String
            Return e
        End Function
    End Class

    Example call:

     Try
                Dim ProjectName As String = CType(control.FindControl("txtPrjt"), TextBox).Text
                'Check validity of ProjectName
                trust = True
                If ProjectName = "" Then
                    Throw New UpdateException("ProjectName" & blank)
                ElseIf Common.NoSQLInj(ProjectName) = False Then
                    Throw New UpdateException(MSG)
                End If

            Catch x As UpdateException
                Dim str As String = x.emessage()
                MsgBox(str)
            Catch Ex As Exception
                Dim emsg As String = ("Our Servers are experiencing high volume. try again.")
                MsgBox(emsg)

            End Try

    Thanks for your time!

    Thursday, July 25, 2013 3:58 PM

All replies

  • User-1454326058 posted

    Hi WillisG,

    Thanks for your post!

    According to your description, I am very sorry that I can not understanding clearly the issue that you have. "The code will work in an individual page as an inline class, but will not recognize class even when I import it, even though I shouldn't have to" that you said, I can't understand. please describe your issues clearly.

    On the other hand, we can realize the common function in a class libraries so that we can use them to anywhere that we want.

    Thanks

    Best Regards

    Saturday, July 27, 2013 12:26 PM
  • User-1454326058 posted

    Hi WillisG,

    Has your issue been solved, please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thanks

    Best Regards

    Thursday, August 1, 2013 8:30 AM