How to number my custom errnos

I return an error code if my program was abnormally terminated (via exit ()). For standard situations, I just return a basic error (e.g. ENOMEM for broken mallocs, etc.). However, there are also cases where I will have to stop working for my own reasons for which system errnos are not defined.

What error values โ€‹โ€‹should I return so that they do not collide with existing ones. Or am I doing all this in return?

edit: I'm sorry if I did not understand the question. I am not talking about listing, etc. (This is a mechanism for determining error codes). I talked about the range of values โ€‹โ€‹that they could accept without encountering standard ones.

I did not know that a program can only return 8-bit statuses. Therefore, it seems that @r is true - it is too small to contain, perhaps even all the standard ones, not to mention my user errors. so 1/0 is :)

+3
source share
5 answers

, , 8 , . , 0/1 (/), , , , , script (, " " ", " ).

+5

, . ?

. ( ) - , . , / , ( /SQL ). - - , .

- , . , :

  • 0 - O.K.,
  • 1 - , (, , ),
  • 2 - config ( ),
  • 3 - ( , ),
  • 4 - (clean/tmp, ).

, , POV , . , , / , , 0 1.

+3

?

- .

+1

.

1) Enums - . , , . , , , API ..

enum
{
ERROR_GROUP_1 =100,// This gives 99 error codes for a particular group, can be initialised to negative value too.
GROUP1_1,
.
.
ERROR_GROUP_2 = 200
GROUP2_2,
.
.
and so on
};

2)

#define ERROR_CODE_START 00000000L

#define ERROR_CODE_1 (ERROR_CODE_START + 1)

3) int, , .

4) โ€‹โ€‹, GError. API . NULL, , API.

+1

, Posix, 0 255. , wait() ( , , 16 ).

In practice, you probably just want some codes, maybe only 0 and 1. Additional information can be transmitted via stderr in a more useful (for humans) text format.

+1
source

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


All Articles