The Autodesk.Revit.Exceptions.ArgumentException class is a type of exception in the Revit API that is thrown when an invalid argument is passed to a method or constructor.
public class ArgumentException : RevitException
System.ArgumentException > System.Exception > Autodesk.Revit.Exceptions.RevitException
| Property | Description |
|---|---|
| Data | Gets a collection of key/value pairs that provide additional user-defined information about the exception. |
| HelpLink | Gets or sets a link to the help file associated with this exception. |
| HResult | Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception. |
| InnerException | Gets the Exception instance that caused the current exception. |
| Message | Gets a message that describes the current exception. |
| Source | Gets or sets the name of the application or the object that causes the error. |
| StackTrace | Gets a string representation of the immediate frames on the call stack. |
| TargetSite | Gets the method that throws the current exception. |
The Autodesk.Revit.Exceptions.ArgumentException is a subclass of the System.ArgumentException and the Autodesk.Revit.Exceptions.RevitException classes. It is used to indicate that an argument is invalid or outside of the acceptable bounds when passed to a method or constructor.
This exception can be raised by almost any method or constructor in the Revit API when an argument is invalid. The exception message will generally contain information about which argument is invalid and why it is invalid.
using Autodesk.Revit.Exceptions;
try
{
// invalid argument passed to method
SomeRevitMethod(null);
}
catch (ArgumentException ex)
{
TaskDialog.Show("Error", ex.Message);
}
In the example above, a SomeRevitMethod method call is made with a null argument. This causes an Autodesk.Revit.Exceptions.ArgumentException to be thrown, which is caught using a try...catch block. The exception message is displayed in a TaskDialog popup.