Quantcast
Channel: Visual Studio and Visual Web Developer Express
Viewing all articles
Browse latest Browse all 3509

RE: Custom Exceptions in ASP.Net 3.5 Web Form

$
0
0

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!


Viewing all articles
Browse latest Browse all 3509

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>