expection handing: error message "undefined symbol try . . " 
January 7th, 2009, 04:01 AM
| | Newbie | | Join Date: Jan 2009
Posts: 4
| | |
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.
| 
January 7th, 2009, 05:48 AM
|  | Expert | | Join Date: Mar 2007 Location: Chennai
Posts: 1,257
| | | re: expection handing: error message "undefined symbol try . . "
Can you post the piece of code where u are getting the error?
Also which compiler u are using?
Raghu
| 
January 7th, 2009, 06:35 AM
| | Newbie | | Join Date: Jan 2009
Posts: 4
| | | re: expection handing: error message "undefined symbol try . . " -
-
//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();
-
}
-
| 
January 7th, 2009, 07:32 AM
| | Administrator | | Join Date: Sep 2006
Posts: 12,084
| | | re: expection handing: error message "undefined symbol try . . "
Are you compiling as c or c++?
Is that the only error message you are getting?
| 
January 7th, 2009, 09:33 AM
| | Newbie | | Join Date: Jan 2009
Posts: 4
| | | re: expection handing: error message "undefined symbol try . . "
then what I should do and how can i run my programme
| 
January 7th, 2009, 10:22 AM
|  | AdministratorVoR | | Join Date: Feb 2006 Location: South West UK
Posts: 6,117
Provided Answers: 6 | | | re: expection handing: error message "undefined symbol try . . "
You should start by re-writing void main() as int main(). Main returns an int, always, anything else is undefined behaviour.
| 
January 7th, 2009, 10:31 AM
| | Administrator | | Join Date: Sep 2006
Posts: 12,084
| | | re: expection handing: error message "undefined symbol try . . " Quote:
Originally Posted by arvindkuk then what I should do and how can i run my programme | I don't think you started learning C++ by learning exceptions. How did you compile your hello world c++ program?
| 
January 7th, 2009, 11:08 AM
| | Newbie | | Join Date: Jan 2009
Posts: 4
| | | re: expection handing: error message "undefined symbol try . . "
my problem is "undefined symbol try" how can I handle this
| 
January 7th, 2009, 11:47 AM
| | Administrator | | Join Date: Sep 2006
Posts: 12,084
| | | re: expection handing: error message "undefined symbol try . . "
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<iostream.h> with #include<iostream>
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.
| 
January 7th, 2009, 12:13 PM
|  | AdministratorVoR | | Join Date: Feb 2006 Location: South West UK
Posts: 6,117
Provided Answers: 6 | | | re: expection handing: error message "undefined symbol try . . "
Something obvious that has not been mentioned yet is what is the name of your file?
if it is <something>.c then the compiler will almost certainly be compiling it as C code it needs to be <something>.cpp
| 
January 7th, 2009, 04:57 PM
| | Moderator | | Join Date: Mar 2007 Location: North Bend Washington USA
Posts: 5,340
| | | re: expection handing: error message "undefined symbol try . . "
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.
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,689 network members.
|