开发者

What are the Best Practices regarding error codes returned by a Console application?

开发者 https://www.devze.com 2022-12-08 22:34 出处:网络
In c# you can return an integer to the underlying caller using Environment.Exit(n) (which can be tested, for instance, using the ERRORLEVEL variable from a DOS script).

In c# you can return an integer to the underlying caller using Environment.Exit(n) (which can be tested, for instance, using the ERRORLEVEL variable from a DOS script).

Are there best practices regarding those codes?

I think 0 = no error... but are there numbers reserved? Can I use negati开发者_如何学Pythonve numbers? etc

Thanks!


Zero usually means that there were no errors. As for others, I don't think there is a reserved set. I would usually define what the different return codes of my application meant and document them.

DOS only handles a maximum of 256 possible return codes, but in reality I doubt you would ever use/need that many.

You can use negative values, but note that negative values do not necessarily mean anything different from positive values.


The most extensive use of return codes I've seen is in Robocopy. It may provide guidance for other apps. Robocopy uses return codes as flags:

0×10 Serious error. Robocopy did not copy any files. This is either a usage error or an error due to insufficient access privileges on the source or destination directories.

0×08 Some files or directories could not be copied (copy errors occurred and the retry limit was exceeded). Check these errors further.

0×04 Some Mismatched files or directories were detected. Examine the output log. Housekeeping is probably necessary.

0×02 Some Extra files or directories were detected. Examine the output log. Some housekeeping may be needed.

0×01 One or more files were copied successfully (that is, new files have arrived).

0×00 No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized.

0

精彩评论

暂无评论...
验证码 换一张
取 消