Java. System.exit (int status). Value for Exit Status

I saw a lot of questions about System.exit(int status) on stackoverflow .

For instance:

The difference in the system. exit (0), System.exit (-1), System.exit (1) in Java

difference between System.exit (0) and System.exit (-1)

But I do not see the answer to my partial question:

Do we have a direct connection between exit status and System Error Codes for Microsoft products ( Microsoft website )?

Of course, we do not have direct connections, but: can we establish this connection?

If we run our java program on Windows, and our java program has a System.exit(int status) statement, can we use System Error Codes list or not?

Is this a good idea or not?

What do you think about it? Any other ideas?

Example:

  • The Java program was launched through the command line on the Wisdows OS;
  • Our java program FileNotFoundException exception, for example FileNotFoundException ;
  • After that, we decided to close our program using System.exit(int state) ;
  • In this case, can exit status be equal to 2 ?

because ( Microsoft Website ):

 ERROR_FILE_NOT_FOUND 2 (0x2) The system cannot find the file specified. 
+6
source share
2 answers

Exit status is the value of your choice. If you call your program and then react based on the value of the output received after its completion, you can handle them at your discretion.

There is only one general rule: exit status 0 assumes that your program terminated without errors. Moreover, a negative exit status is usually considered termination due to an unexpected error, while a positive exit status is considered a more or less elegant ending.

But then again: if there is no batch file that calls your code, no one will respond to the exit status, and so you can return whatever you want, it will have no effect.

+7
source

The exit code is just informative and can be based on your design. Microsoft codes are important because MS software may try to recognize them, just like Linux, there is a different set of predefined consistent codes. It will not hurt to use one of the sets.

+2
source

Source: https://habr.com/ru/post/955883/


All Articles