Constructors: NewArgumentException

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

Parameters

Message
[ByRef] String. A human-readable message explaining the exception.
ParamName
[ByRef] Optional. String. The parameter that caused the exception.
InnerException
[ByVal] Optional. Exception. An exception that caused this exception.

Return Values

ArgumentException -  A fully created ArgumentException object.

Remarks

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.

Examples

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

See Also

Project CorLib Overview

Class Constructors Overview

ArgumentException