Use Argument Exception

Imports System
Imports System.Collections
Public Class MainClass
Shared Sub Main(ByVal args As String())
Try
Dim rect As New DrawableRectangle(10, 20, 0, -100)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
End Class
Public Class DrawableRectangle
Public Sub New(ByVal new_x As Integer, ByVal new_y As Integer, ByVal new_width As Integer, ByVal new_height As Integer)
' Verify that new_width > 0.
If new_width <= 0 Then
' Throw an ArgumentException.
Dim ex As New ArgumentException( _
"DrawableRectangle must have a width greater than zero", _
"new_width")
Throw ex
End If
' Verify that new_height> 0.
If new_height <= 0 Then
' Throw an ArgumentException.
Throw New ArgumentException( _
"DrawableRectangle must have a height greater than zero", _
"new_height")
End If
End Sub
End Class
Related examples in the same category