Software Archive
Read-only legacy content

Exit Code

vivekbedekar
Beginner
963 Views
Hi,
When a program terminates I get a message like 'Program .. has exited with code 0.' Could anyone please help me finding all the possible code values with which a program can exit.
Thanks,
Vivek
0 Kudos
7 Replies
Steven_L_Intel1
Employee
963 Views
The exit code can be anything. 0 usually means success. It's entirely up to the program to specify what the exit code is - in Fortran, you'd use CALL EXIT to set this.

Steve
0 Kudos
Intel_C_Intel
Employee
963 Views
You get this message when your code hits a STOP statement. If you
want a different code you can say, for example: STOP 2000, and then
the message will be '...exited with code 2000'. You can, as an alternative,
use text: STOP 'your message goes here'.
0 Kudos
Steven_L_Intel1
Employee
963 Views
Actually, the STOP statement doesn't set the exit value.

Steve
0 Kudos
vivekbedekar
Beginner
963 Views
Thanks. But if there is no exception handling, would the error code always be negative?
Vivek
0 Kudos
vivekbedekar
Beginner
963 Views
sorry, in the last message it should have been 'exit code' not error code.
Vivek
0 Kudos
Intel_C_Intel
Employee
963 Views
To Steve L.: Maybe we are not talking about the same thing, but from the
form of the message he is getting it sounds like what happens in
windows when it hits a stop statement. From the on-line docs:

STOP
Statement: Terminates program execution before the end of the program unit.

Syntax

STOP [stop-code]

stop-code
(Optional) A message. It can be either of the following:

A scalar character constant of type default character.
A string of up to six digits; leading zeros are ignored. (Fortran 95/90 and FORTRAN 77 limit digits to five.)
Effect on Windows Systems

If you specify stop-code, the effect differs depending on its form, as follows:

If stop-code is specified as a character constant, the STOP statement writes the specified message to the standard error device and terminates program execution. The program returns a status of zero to the operating system.

If stop-code is specified as a string of digits, the STOP statement writes the following to the standard error device and terminates program execution:
Return code stop-code
In QuickWin programs, the following is displayed in a message box:
Program terminated with Exit Code stop-code
In both cases, the program returns a status of stop-code to the operating system as an integer.
0 Kudos
Steven_L_Intel1
Employee
963 Views
Ah, I had forgotten that STOP nnnnn would turn that into an exit status.

I have noticed that QuickWin programs tend to have their threads exit with a status of -1, and the main program zero. If the exit status is greater than zero, that's the time to wonder what else happened.

Steve
0 Kudos
Reply