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 |
What is the difference between far and near in c?
how to find the kth smallest element in the given list of array elemnts.
Can we use visual studio for c?
Can we change the value of #define in c?
a linearly ordered set of data elements that have the same structure and whose order is preserved in storage by using sequential allocation a) circular b) ordinary c) array d) linear list
2) Write a program that will help Air Traffic Control for an airport to view the sequence of flights ready for take-off. The airport can accommodate 10 flights waiting for take-off at any point in time. Each flight has a unique 3 digit numeric identifier.  Each time a flight takes-off, Air Traffic Control adds a flight to the waitlist. Each time a flight is added to the waitlist, the list of flights waiting to take-off must be displayed.  When a flight is cleared for take-off, Air Traffic Control removes the flight from the waitlist. Each time a flight takes-off, the list of flights waiting to take-off must be displayed.  Sequence of take-off is the sequence of addition to the waitlist
How can we see the Expanded source code and compiled code for our source program in C?
What is main void in c?
write a c program to print a given number as odd or even without using loop statements,(no if ,while etc)
Explain what happens if you free a pointer twice?
progrem to generate the following series 1 12 123 1234 12345
Is the C language is the portable language...If yes...Then Why...and if not then what is problem so it is not a Portable language..???