HOW TO HANDLE EXCEPTIONS IN C
Answers were Sorted based on User's Feedback
Answer / chandan
There is no try,catch(available in C++,java..) facility to
handle exception in C.but we can handle exception by
validating data come from outside into the program.
eg.. cosider this code
void main(){
int a,b,div;
scanf("%d,%d",a,b)
div=a/b;
printf("%d",div);
}
int this case , b might be zero that will generate an
exception.so we can avoid it by using if statement.
if(b==0)
print("plz enter non zero value");
In this manner only we can prevent exception in C..
Thank you
| Is This Answer Correct ? | 6 Yes | 2 No |
Answer / bhupendra
i can not handle exception in C.When exception occue in C
the sustem will terminated.
| Is This Answer Correct ? | 2 Yes | 2 No |
Answer / eok
in C you dont have the luxury of the try and catch , unless
you get a non standard library
There is a way to handle errors
C works directly with the machine , so you must make a
function that will take whatever is causing the problem in
the buffers and remove it or clear the buffer altoeghter ,
although clearing the entire buffer can be over zealous
try using ungetc to remove stray pieces from the buffer
but again this really comes down to what error your trying
to deal with
also look at perror and strerror and the libraries errno.h
and stderr.h
hope this helped
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / vrushali
i feel perror would work for it..
please corect me if i m wrong
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / sivakumar
I was searching for this answer for a long time but I
couldn't get it so pls guide me if possible.....
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / padma
c dont have that much capacity to handle errors...
| Is This Answer Correct ? | 0 Yes | 2 No |
Answer / chandan kiit
There is no try,catch(available in C++,java..) facility to
handle exception in C.but we can handle exception by
validating data come from outside into the program.
eg.. cosider this code
void main(){
int a,b,div;
scanf("%d,%d",a,b)
div=a/b;
printf("%d",div);
}
int this case , b might be zero that will generate an
exception.so we can avoid it by using if statement.
if(b==0)
print("plz enter non zero value");
In this manner only we can prevent exception in C..
Thank you
| Is This Answer Correct ? | 0 Yes | 4 No |
which type of question asked from c / c++ in interview.
What is difference between && and & in c?
Given an array of 1s and 0s arrange the 1s together and 0s together in a single scan of the array. Optimize the boundary conditions?
What is the data segment that is followed by c?
the format specified for hexa decimal is a.%d b.%o c.%x d.%u
How can I use a preprocessorif expression to ?
#include<stdio.h> #include<conio.h> int main() { int a[4][4]={{5,7,5,9}, {4,6,3,1}, {2,9,0,6}}; int *p; int (*q)[4]; p=(int*)a; q=a; printf("\n%u%u",p,q); p++; q++; printf("\n%u%u",p,q); getch(); return 0; } what is the meaning of this program?
What is a c token and types of c tokens?
WHAT IS THE DEFINATION OF IN TECHNOLOGY AND OFF TECHNOLOGY ?
A function 'q' that accepts a pointer to a character as argument and returns a pointer to an array of integer can be declared as: A)int (*q(char*)) [] B)int *q(char*) [] C)int(*q)(char*) [] D)None of the Above
though sbi was nationalized why its not comes under nationalized banks and its comes under publicsector banks
3 Answers State Bank Of India SBI,
Explain the difference between structs and unions in c?