1. error handle
errno:
contain the predefined error number macro return by a system call.
defined in
2. useful macro for error message
2.1 __FILE__
defined macro, it is a string(char *) contained file name.
2.2 __FUNC__ or __func__
defined macro, it is a string(char *) contained function name.
2.3 __LINE__
defined macro, it is a integer contained line number.
we could use these macro in debug, and they will be very helpful for us
to locate error raising place.
3. useful functions for error handle
3.1 perror
#include
void perror(const char *s);
Output the *s, then :, then a blank, at last give out the
systen predefined error message referring to errno value.
Example:
errno = EACCES;
perror("Error: ");
Output:
Error Message: Permission denied
3.2 strerror
#include
char *strerror(int errnum);
return a string(char *) that contains systen predefined error message
referring to the errno value.
Example:
errno = EACCES;
printf("Error Message: %s\n", strerror(errno));
Output:
Error Message: Permission denied
阅读(537) | 评论(0) | 转发(0) |