Throw Exception in Property setter (VB.net) : Property « Language Basics « ASP.Net






Throw Exception in Property setter (VB.net)

<%@ Page Language="VB" %>
<script runat="server">

Public Class Math
    Private intValue As Integer
    Public Property InValue() As Integer
        Get
            Return intValue
        End Get
        Set(ByVal value As Integer)
            If intValue > 0 Then
                intValue = value
            Else
                Throw New Exception("InValue can not be less than 1")
            End If
        End Set 
    End Property

    Public Function MultiplyBySelf(ByVal InValue As Integer) As Integer
        Return Multiply(InValue, InValue)
    End Function

    Private Function Multiply(ByVal FirstValue As Integer, ByVal SecondValue As Integer)
        Return FirstValue * SecondValue
    End Function

End Class

    Sub Page_Load()
        Dim clsMath As Math
        clsMath = New Math
        clsMath.InValue = 10
        lblMessage.Text = clsMath.MultiplyBySelf(10)
    End Sub
    
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Show Shared Hello World</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    <asp:Label
        id="lblMessage"
        Runat="server" />
    
    </div>
    </form>
</body>
</html>

           
       








Related examples in the same category

1.Define and use properties (C#)
2.Properties for read and write (C#)