Chinaunix首页 | 论坛 | 博客
  • 博客访问: 255940
  • 博文数量: 65
  • 博客积分: 2599
  • 博客等级: 少校
  • 技术积分: 710
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-04 10:49
文章分类

全部博文(65)

文章存档

2015年(4)

2013年(2)

2012年(4)

2011年(51)

2010年(4)

分类: LINUX

2011-12-16 13:55:46

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
阅读(533) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~