In a C# program, what is the exit code defined to be when an exception in thrown out of main
? I know you can set the exit code in a number of ways as documented in this excellent answer. But I'm very surprised that I can't find documentation for what the value of the exit code is defined to be when an exception is thrown out of main. Is there a standard that defines what the value of the exit code will be in this case, or does it depend upon the operating system (or chance, or anything else)?
An exit code, or sometimes known as a return code, is the code returned to a parent process by an executable. On POSIX systems the standard exit code is 0 for success and any number from 1 to 255 for anything else. Exit codes can be interpreted by machine scripts to adapt in the event of successes of failures.
What the Problem Means. The short answer is that the program did not return a zero as its exit or return code. Waf reports this back in red since it usually means that the program has failed in some way.
The exit() function is used to terminate program execution and to return to the operating system. The return code "0" exits a program without any error message, but other codes indicate that the system can handle the error messages. Syntax: void exit(int return_code);
C library function - exit()The C library function void exit(int status) terminates the calling process immediately. Any open file descriptors belonging to the process are closed and any children of the process are inherited by process 1, init, and the process parent is sent a SIGCHLD signal.
I observe -532462766
PS C:\Projects\Throw\Throw\bin\Debug> .\Throw.exe
Unhandled Exception: System.Exception: Exception of type 'System.Exception' was thrown at Throw.Program.Main(String[] args) in c:\Projects\Throw\Throw\Program.cs:line 13
PS C:\Projects\Throw\Throw\bin\Debug> $LASTEXITCODE
-532462766
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With