Hello
How do I catch the error which are thrown in the class?
I have a class as follows:
Namespace ErrorClass1
PublicClass Class1
Private mId AsInteger
PublicProperty Id() AsInteger
Get
Return mId
EndGet
Set(ByVal Value AsInteger)
Try
mId = Value
Catch ex As Exception
ThrowNew Exception("Error: Id value should be interget : Source= " + ex.Source + " : Message= " + ex.Message)
EndTry
EndSet
EndProperty
PublicFunction Add() AsInteger
Try
Return mId + 200
Catch ex As Exception
ThrowNew Exception("Error: Add method : Source= " + ex.Source + " : Message= " + ex.Message)
EndTry
EndFunction
EndClass
EndNamespace
This above class I'm importing in a Windows application as follows:
Imports [Error].ErrorClass1
Imports System.Exception
PublicClass Form1
Inherits System.Windows.Forms.Form
FriendWithEvents TextBox1 As System.Windows.Forms.TextBox
FriendWithEvents Button1 As System.Windows.Forms.Button
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x AsNew Class1
Try
x.Id = TextBox1.Text
MessageBox.Show(x.Add.ToString())
Catch ex As Exception
' My question is how do I catch the above marked red color error message while initilizing the above class.
EndTry
EndSub
Please suggest me how do I go about it.
How do I catch the error which are thrown in the class?
I have a class as follows:
Namespace ErrorClass1
PublicClass Class1
Private mId AsInteger
PublicProperty Id() AsInteger
Get
Return mId
EndGet
Set(ByVal Value AsInteger)
Try
mId = Value
Catch ex As Exception
ThrowNew Exception("Error: Id value should be interget : Source= " + ex.Source + " : Message= " + ex.Message)
EndTry
EndSet
EndProperty
PublicFunction Add() AsInteger
Try
Return mId + 200
Catch ex As Exception
ThrowNew Exception("Error: Add method : Source= " + ex.Source + " : Message= " + ex.Message)
EndTry
EndFunction
EndClass
EndNamespace
This above class I'm importing in a Windows application as follows:
Imports [Error].ErrorClass1
Imports System.Exception
PublicClass Form1
Inherits System.Windows.Forms.Form
FriendWithEvents TextBox1 As System.Windows.Forms.TextBox
FriendWithEvents Button1 As System.Windows.Forms.Button
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x AsNew Class1
Try
x.Id = TextBox1.Text
MessageBox.Show(x.Add.ToString())
Catch ex As Exception
' My question is how do I catch the above marked red color error message while initilizing the above class.
EndTry
EndSub
Please suggest me how do I go about it.