how to work with expection handing in which when i am using try block then the error message coming that "undefined symbol try" why it is so, please solve my problem.
exception handing: error message "undefined symbol try . . "
Collapse
X
-
Can you post the piece of code where u are getting the error?
Also which compiler u are using?
Raghu -
c++
Code://Compile is turbo c++ #include<iostream.h> #include<stdio.h> #include<conio.h> void main() { clrscr(); int a,b; cout<<"Enter value of a and b\n"; cin>>a>>b; int x=a-b; try { if(x!=0) { cout<<"Result(a/x)="<<a/x<<endl; } else { throw(x); } } catch(int i) { cout<<"Exption caughg:x="<<x<<endl; } cout<<"End"; getch(); }Comment
-
Your problem is not being sure which language you are coding in. You want to use try/catch exception handling so you must use c++ not c.
For c++ you need to change these things
1.) replace #include<iostre am.h> with #include<iostre am>
2.) Remove all other includes
3.) add using namespace std; before the definition of main
4.) Make main return an int not void. void is wrong even in c
5.) Remove lines with clrscr(); and getch(); in your code
6.) Compile the file as a c++ file not as a c source file.Comment
-
Also, keep in mind that exception handling is often turned off in most C++ compilers by default. You have have to enable it by setting a compiler switch.
That would explain your indefined symbol.Comment
Comment