I cannot understand what the errno library in c++ is for? What types of errors are set in it and how do I know which number stands for which error?
Does it affect program execution?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
errno.h is part of the C subset of C++. It is used by the C library and contains error codes. If a call to a function fails, the variable “errno” is set correspondingly to the error.
It will be of no use if you’re using the C++ standard library.
In C you have functions that translate errno codes to C-strings. If your code is single threaded, you can use strerror, otherwise use strerror_r (see http://www.club.cc.cmu.edu/~cmccabe/blog_strerror.html)
For instance in C it works like this:
You may need it of course in C++ when you’re using the C library or your OS library that is in C. For instance, if you’re using the sys/socket.h API in Unix systems.
With C++, if you’re making a wrapper around a C API call, you can use your own C++ exceptions that will use errno.h to get the corresponding message from your C API call error codes.