Correct usage of exit() in c++?

后端 未结 6 1203
再見小時候
再見小時候 2021-02-12 10:31

I have written a simple application that reads a data file, parses the text and then does some processing on that data. The data file is opened in my main() function. Is it good

6条回答
  •  别那么骄傲
    2021-02-12 11:13

    It depends on where that exit(1) comes from. You should not call this exit(1) from a library, only from you own application.

    If you need to set an error code, you may set an errno (the STD C variable, yes).

    If you want to try a more C++ way, you can throw an exception, with a detailed error code.

提交回复
热议问题