Using Environment.ExitCode versus returning int from Main

后端 未结 3 1112
离开以前
离开以前 2021-01-04 07:23

I am planning to use the return code of the C# executable in one of my shell script. I have two options:

Returning a int value from the main method<

3条回答
  •  孤独总比滥情好
    2021-01-04 08:07

    Environment.Exit() is a rude abort. It instantly terminates the process. Use it only when you detect a gross failure, it is appropriate in an AppDomain.UnhandledException event handler for example. Which runs when your program is about to terminate because of an unhandled exception.

    Which is your lead: exceptions are a good way to signal unusual conditions that should terminate the program with an ExitCode that isn't zero. In fact, it automatically gets set to the HResult property value of the exception. No code required.

提交回复
热议问题