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 |
for example user gives input as " 20 or 20.0 or rs 20.0 or 20.00 or rs20 and so .. on " and the output should be stored as " rs.20.00 " in a variable
5. What kind of sorting is this: SORT (k,n) 1.[Loop on I Index] repeat thru step2 for i=1,2,........n-1 2.[For each pass,get small value] min=i; repeat for j=i+1 to N do { if K[j]<k[min] min=j; } temp=K[i];K[i]=K[min];K[min]=temp; 3.[Sorted Values will be returned] A)Bubble Sort B)Quick Sort C)Selection Sort D)Merge Sort
exit () is used to a) exit () terminates the execution of the program itself b) exit () terminates the execution of the loop c) exit () terminates the execution of the block d) none of the above
hi any body pls give me company name interview conduct "c" language only
Is the below things valid & where it will be stored in memory layout ? static const volatile int i; register struct { } ; static register;
write a c code "if you give a any decimal number then print that number in english alphabet"? ex: i/p: 552 o/p: five hundred fifty two ...
How many loops are there in c?
Write a program to identify if a given binary tree is balanced or not.
a linear linked list such that the link field of its last node points to the first node instead of containing NULL a) linked list b) circular linked list c) sequential linked list d) none
Is it better to bitshift a value than to multiply by 2?
what is the output of the code and how? main() { int *ptr,x; x=sizeof(ptr); printf("%d",x); }
What are the usage of pointer in c?