Saturday, December 1, 2012

Returning Command Line Errors

When the starting of the single shot time to force the application to quit upon entering the event loop was replaced by a simple return (of 0), I realized that it should really be returning an error code if there is an error in the command line options.

To accomplish this, the processed flag in the CommandLine class was replaced with return code variable, which has three values: 0 for successfully processed command line only option, 1 for error occurred with the command line options, and -1 for no command line only options (in other words, start the GUI).  An access function was added for the return code.

The processed access function remains (so callers don't need to be modified), but now returns true if the return code variable is not negative.  A return code variable was also added to the MainWindow class along with an access function.  In the constructor, the return code is obtained from the command line instance when the GUI active flag is set to false (when the command line was processed).  The main function was modified to return this code.

By convention, a command returns a code of 0 to indicate success and any other value to indicate an error.  Some commands return a specific error code value, but here just a general error occurred code (1) is returned.  To test if this new functionality was working correctly, this command was used:
ibcp -v && echo no error
This command will output the version number followed by the "no error" message.  If the -v is replaced with an invalid option, the "no error" message will not be output.

[commit 164fb19fe8]

No comments:

Post a Comment

All comments and feedback welcomed, whether positive or negative.
(Anonymous comments are allowed, but comments with URL links or unrelated comments will be removed.)