Skip to content

Understanding exceptions

JF Blouin edited this page Apr 10, 2019 · 11 revisions

Exceptions thrown by the library fall into one of the two following categories: parse exceptions and execution exception. Both exceptions will provide detail about the error by checking the OperationMessages property.


Parsing error: CommandLineEngineDevelopperException

This exception is thrown when the configuration of available commands is invalid. These errors do not depend on the arguments recieved, simply based on discovery of available commands and parameters. They require code changes by the developper to fix.

When loading the code, the library performs the following check, and will raise an error in invalid check:

  1. Scan all methods in the types specified.
  2. Ensure there is at least one command.
  3. Ensure there is at most one default command.
  4. Ensure no command name have spaces in them.
  5. Ensure no command are reserved keywords (by default: --help, -h, ?).
  6. Ensure all commands have distinct names.
  7. Ensure all custom validation rules are valid. See Applying custom rules when parsing commands
  8. Evaluate command parameters.
    1. Ensure all parameters have distinct names.
    2. Ensure no parameters have spaces space in them.
    3. Ensure no parameters are reserved keywords (by default: --help, -h, ?).

Execution error: CommandLineEngineException

This exception is thrown when validating input arguments (from user) and executing commands. Most cases of invalid arguments will simply print the help on how to use your application, but some cases can throw errors.

  1. Invalid type is recived (command line argument is converted from string to the type specified in the method using Convert.ChangeType()).
  2. Can not find a public non-empty constructor (in case command is not static).
  3. Any exceptions raised in your logic.

I recommand leaving method parameters as string and performing the cast yourself.

Clone this wiki locally