Class CommandLineException
- Namespace
- Invex.Atom.Build.Exceptions
- Assembly
- Invex.Atom.Build.dll
Thrown when command-line arguments are invalid or malformed.
public class CommandLineException : AtomException
- Inheritance
-
objectExceptionCommandLineException
Examples
Example 1: Throwing for an argument-related failure
throw new CommandLineException("Parameter 'output' could not be resolved to a valid path.")
{
ArgumentName = "output"
};
Example 2: How to catch and provide user guidance
try
{
await executor.Execute(cancellationToken);
}
catch (CommandLineException ex)
{
Console.WriteLine($"Invalid arguments: {ex.Message}");
if (ex.ArgumentName is not null)
{
Console.WriteLine($"Problematic argument: {ex.ArgumentName}");
}
Console.WriteLine("Run with --help for usage information.");
Environment.ExitCode = 2;
}
Remarks
This exception signals that build execution cannot proceed because of a problem with the command-line input. Note that Invex.Atom.Build.Args.CommandLineArgsParser itself does not throw; it collects parse problems as ParseError objects on Errors, which are reported once the application host is fully constructed. This exception is reserved for argument-related failures detected later, such as during parameter resolution.
The ArgumentName property, when set, identifies the specific command-line argument that caused the error, making it easier to diagnose and fix the issue.
For help with command-line usage, run the build with the --help flag.
Constructors
CommandLineException()
Initializes a new instance of the CommandLineException class.
public CommandLineException()
CommandLineException(string)
Initializes a new instance of the CommandLineException class with a specified error message.
public CommandLineException(string message)
Parameters
messagestringThe message that describes the error.
CommandLineException(string, Exception)
Initializes a new instance of the CommandLineException class with a specified error message and a reference to the inner exception that is the cause of this exception.
public CommandLineException(string message, Exception innerException)
Parameters
messagestringThe error message that explains the reason for the exception.
innerExceptionExceptionThe exception that is the cause of the current exception, or null if no inner exception is specified.
Properties
ArgumentName
Gets the name of the command-line argument that caused the error, if applicable.
public string? ArgumentName { get; init; }
Property Value
- string
Remarks
This property helps identify which specific argument was problematic, making it easier to diagnose
and fix command-line issues. For example, if the --project option is missing its value,
this property would be set to "project".