Synopsis: | Check for all errors reported from functions |
Language: | C++ |
Severity Level: | 6 |
Category: | Error Handling |
Description: |
If an error reported this way is ignored, there is no easy way of knowing what eventually made the program crash. It seems natural to check status values returned from functions, but in reality there are huge amounts of code written that does not do these checks. The fact that status values can be ignored by the programmer is one of the reasons to why exception handling in most cases is a better way of reporting errors. Example: // create socket int socketfd = socket(AF_UNIX, SOCK_STREAM, 0); if (socketfd < 0) // check status value { // ... } Using (void) to cast-away the return value is allowed. (void) FunctionWithReturnValue(); |