- Introduction to C error handling in Hindi
- perror() function for C error handling in Hindi
- strerror() function for C error handling in Hindi
Introduction to C Error Handling
errno Variable
extern int errno;
|
Functions for Error Handling
- perror() – ये function आपके द्वारा pass की गयी string को print करता है और साथ ही जो error generate हुई है उसका description print किया जाता है। इस function से ये पता चल जाता है की कौनसी error आयी है।
- strerror() – ये function generate की गयी error के textual representation का pointer return करता है। ये function standard errors को point करता है।
#include <stdio.h>
#include <errno.h>
extern int errno;
int main()
{
FILE *fp;
fp = fopen(“test.txt”,”r”);
/* Checking for error, whether file is loaded or not */
if(fp == NULL)
{
/* Printing error number & description */
fprintf(stderr,”Error Number : %dn”,errno);
perror(“Error Description : “);
}
else
{
fclose(fp);
}
}
|
Error Number : 2
Error Description : No such file or directory
|
exit() Function
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
extern int errno;
int main()
{
FILE *fp;
fp=fopen(“test.txt”,”r”);
/* Checking for error */
if(fp == NULL)
{
fprintf(stderr,”Error Number : %d”, errno);
perror(“Error Description “);
fprintf(stderr,”Exiting due to error….”);
/* Exiting program due to error */
exit(-1);
}
else
{
fclose(fp);
}
}
|
Error Number : 2
Error Description : No such file or directory
Exiting due to error…..
|
Next: C header files
कोई टिप्पणी नहीं:
एक टिप्पणी भेजें