The simplest solution is to send Submit (), returning a boolean value indicating whether the error was or not:
If class.Submit() = False Then lblError.Text = "Hey, that is not right." End If
It is good practice that your class is responsible for its errors, in which case you will find the error message property:
If class.Submit() = False Then lblError.Text = class.GetErrorMessage() End If
The Submit function will look something like this:
Public Function Submit() As Boolean Dim success As Boolean = False Try ' Do processing here. Depending on what you do, you can ' set success to True or False and set the ErrorMessage property to ' the correct string. Catch ex As Exception ' Check for specific exceptions that indicate an error. In those ' cases, set success to False. Otherwise, rethrow the error and let ' a higher up error handler deal with it. End Try Return success End Function
source share