开发者

exit status on incorrect usage

开发者 https://www.devze.com 2023-02-28 17:17 出处:网络
I have a check in my program to see if the user supplies the right amount of command line arguments. If they do not, I print a usage message a开发者_如何学Gond then exit the program.

I have a check in my program to see if the user supplies the right amount of command line arguments. If they do not, I print a usage message a开发者_如何学Gond then exit the program.

However I'm not sure if I should exit with EXIT_SUCCESS or EXIT_FAILURE - it appears that they both have some merit in terms of their english meaning. Is there an important distinction? What should I do?


I personally use EXIT_FAILURE, since it's not a normal usage of your program.


I would return an error code, that is, a non zero value. What value it is, well, that's up to you.


If the program is used in shell scripts, then returning an error (non-zero) value allows the script to determine whether your program did the thing it was supposed-to or not.

Another approach to see what to do is to look at the messages you are producing. If they include words like "error" or "failure", then don't have the program return a value that indicates success.

0

精彩评论

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