HOW TO HANDLE EXCEPTIONS IN C

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What’s the special use of UNIONS?

870


What is table lookup in c?

833


Create a simple code fragment that will swap the values of two variables num1 and num2.

1033


How many levels of indirection in pointers can you have in a single declaration?

820


What language is lisp written in?

842


Give the rules for variable declaration?

918


How to write a code for reverse of string without using string functions?

1825


What are the advantages of using new operator as compared to the function malloc ()?

1052


What are header files in c?

807


Explain modulus operator. What are the restrictions of a modulus operator?

814


What is data structure in c programming?

793


write a program which the o/p should b in such a way that s triangle if I/p is 3,a Square/rectangle if I/P=4,a pentagon if I/P=5 and so on...forget about the I/P which is less than 3

1850


What is the use of extern in c?

837


Why void is used in c?

764


Why pointers are used?

825