Constructors: NewArgumentException |
Creates a new ArgumentException object.
Public Function NewArgumentException( ByRef Message As String, Optional ByRef ParamName As String, Optional ByVal InnerException As Exception ) As ArgumentException
When throwing an ArgumentException a meaningful error message describing the invalid argument, the name of the argument, as well as the expected range of values for the argument should be defined.
The example demonstrates various methods for creating and throwing an ArgumentException object.
Public Sub Main() ' Throws a default ArgumentException object Throw New ArgumentException ' Throws an ArgumentException with a custom message and parameter name Throw Cor.NewArgumentException("The argument is incorrect.", "MyParam") ' Throws an ArgumentException with a custom message and error code and parameter name Dim ex As ArgumentException Set ex = Cor.NewArgumentException("The argument is incorrect.", "MyParam") ex.HResult = 123 Throw ex End Sub