हिंदी माध्यम नोट्स
Categories: C Language in hindi
C 99 – Error Handling Macro in c language in hindi , errno , sterror () , assert , Bounce Checking
errno , sterror () , assert , Bounce Checking , C 99 – Error Handling Macro in c language in hindi :-
जब किसी statement के excute होता है अगर कभी error आ जाती है |उस error को handel करने के लिए error macro का use किया जाता है | error macro का use करने के लिए error.h header file को प्रोग्राम मे add करना पड़ता है |error.h मे include सभी macro निन्म है :-
1. errno
errno एक preprocessor होते जो अलग अलग error को expand करता करता है |उन error के लिए विशेष code निधारित किया गया है |जिसे प्रोग्राम मे direct use किया जा सकता है |प्रोग्राम मे किसी variable की value को उन error code से check करके error को find कर सकते है |सबसे errno को ‘0’ से set करते है |अगर प्रोग्राम मे कोई error नहीं आती है तब errno की value ‘0’ होती है अन्यथा इसकी value पूर्व निधारित error code की होती है |
Error code :
1.i- errno== EDOM : डोमेन error आ जाती है |
1.ii-errno== EILSEQ : illegal sequence की error आ जाती है |
1.iii- errno== ERANGE : range error आ जाती है |
सभी error code header file error.h मे define होते है |सभी error code के लिए एक निधारित integer value होती है |और उनकी पूर्व निधरित statement भी होते है |जैसे
1. EDOM : arithmetic argument out of domain
2. EILSEQ : illegel bytes code
3. ERANGE : result too large
उदाहरण के लिए :
#include<stdio.h>
#include<conio.h>
#include<error.h>
void error ();
void main()
void main()
{
pritnf(“Mathematics Error “);
errno = 0 ;
1/0;
error();
errno=0;
log(0);
error();
errno=0;
acos(2.1);
error();
errno= 0;
sin(0);
error();
getch();
}
void error()
{
if(errno== EDOM);
if(errno== EDOM);
printf(“Domain Error “);
if(errno== EILSEQ)
printf(“Illegal sequence error”);
if ( errno== ERANGE )
printf(” Range error”);
if(errno==0)
printf(“No error”);
}
इस उदहारण में ,
अगर ‘1’ को ‘0’ से डिवाइड करते है तब range error की facility होती है |
अगर sin(0) की value infinite होती है तब domain error आ जाती है |
आउटपुट होगा :-
Mathematics Error
Range error
Illegal sequence error
Domain Error
2. sterror ()
इस macro का use , error code की pre set statement को use करने के लिए किया जाता है |इसका syntax होता है :-
sterror();
इसका उदाहरण है :
इस उदाहरण मे error() function को use नहीं किया गया है क्योकि इसमें error की pre set statement को use किया जाता है |
#include<stdio.h>
#include<conio.h>
#include<error.h>
void main()
{
pritnf(“Mathematics Error “);
errno = 0 ;
1/0;
sterror();
errno=0;
log(0);
sterror();
errno=0;
acos(2.1);
sterror();
errno= 0;
sin(0);
sterror();
getch();
}
आउटपुट होगा :
Mathematics Error
result too large
illegal bytes code
arithmetic argument out of domain
3. assert
Assert macro की value NDEBUG की value पर निर्भर करते है |और NDEBUG की definition statndard library मे define नहीं होती है |इसलिए NDEBUG को प्रोग्राम के header part मे include करना होता है |अगर NDEBUG को declare नहीं किया तो assert भी काम नही करता है |
अगर NDEBUG को define नहीं किया तो और assert बकी value ‘0’ के equal हो जाती है तब प्रोग्राम code related error message देता है |और abort () को call कर देता है |code related error message मे कई सारी standard value जैसे file name , variable size, no ऑफ़ argument आदि include होते है |
इसका उदाहरण है :
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<assert.h>
#define NDEBUG
void main()
{
int a,b,c;
printf(“data”);
c=a-b;
pritnf(“Mathematics Error “);
assert (c>=0)
printf(“sqrt(c)= %d”, sqrt(c));
getch();
}
इस उदाहरण का आउटपुट होगा :-
अगर NDEBUG को define नहीं किया तो
data 23 45
a.out sub.c: main: assertion ‘c>=0’ failed
अगर NDEBUG को define किया गया है तो
data 23 45
sqrt(c)= -nan
4. Bounce Checking
Bounce Checking error कुछ specific function की error को check करने के लिए किया जाता है | वे function string related होते है जैसे
gets() , strcpy() , wcscpy() होते है |
इसके अलावा fopen() के लिए bouce check करता है |इसका मतलब है file name की existence को check करता है |
इसके अलावा quick sort algorithm मे use होता है |जिसमे no of pass को check किया जाता है |
ये function को main() प्रोग्राम मे declare करना जरुरी नहीं है |ये उसी condition लागु होता है जब STDC_LIB_EXT1 occur होता है |इस function मे , निन्म macro include होते है :-
(i) error_t
यह एक typedef है जिसका type integer होता है ये macro check file की existence को check करता है |इसमें अलग अलग pre set error message होते है जो error के occur होने पर print होते है |
(ii) rsize_t
यह एक typedef है जिसका type integer होता है ये macro check string की size को check करता है |इसमें अलग अलग pre set error message होते है जो error के occur होने पर print होते है |
(iii) RSIZE_MAX
ये सबसे बड़ी bouce value को check करता है |ये variable की size और constant की value को check करता है जब ये run time पर allocate होते है |
(iv) Set _ constraint_handler_s ,constraint_handler_t
ये statement handler को define करता है जब bounds check function error_t , rsize_t और RSIZE_MAX run time पर occur होते है |और handler variable का type constraint_handler_t होना चाहिए |जैसे
constraint_handler_t ( const char *message ,void *p , error_t error);
यहा पर
const char *message : ये pointer charecter string को point करता है जो की error आने पर print होगा |
void *p : यर pointer implementation defined object को point करता है |
error_t error : ये function से आने वाली error को define करने के लिए किया जाता है |लेकिन ये तब होगा जब function से error_t occur होता है |
(v) abort_handler_s()
जब bounds check function error_t , rsize_t और RSIZE_MAX run time पर occur होते है तब इस handler से प्रोग्राम त्येर्मिनाते हो जाता है | और handler variable का type abort_handler_s होना चाहिए |लेकिन जैसे
abort_handler_s ( const char *message ,void *p , error_t error);
यहा पर
const char *message : ये pointer charecter string को point करता है जो की error आने पर print होगा |
void *p : यर pointer implementation defined object को point करता है |
error_t error : ये function से आने वाली error को define करने के लिए किया जाता है |लेकिन ये तब होगा जब function से error_t occur होता है |
ये सभी error macro को क९९ मे include किया गया है जो की कई दुसरे programming language से include किया गया है |
Recent Posts
सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है
सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…
21 hours ago
मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the
marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…
21 hours ago
राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए sources of rajasthan history in hindi
sources of rajasthan history in hindi राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए…
3 days ago
गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है ? gurjaratra pradesh in rajasthan in hindi
gurjaratra pradesh in rajasthan in hindi गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है…
3 days ago
Weston Standard Cell in hindi वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन
वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन Weston Standard Cell in…
3 months ago
polity notes pdf in hindi for upsc prelims and mains exam , SSC , RAS political science hindi medium handwritten
get all types and chapters polity notes pdf in hindi for upsc , SSC ,…
3 months ago