473,387 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

undefined try symbol

What should I do if ma compiler says undefined symbol try during exception handling??
Sep 25 '13 #1

✓ answered by Nepomuk

There are a few things wrong with that code, so let's go through them one by one:
  • If you want to use cin and cout without adding the namespace to every call (which would be std::cin and std::cout) you'll have to use that namespace by adding
    Expand|Select|Wrap|Line Numbers
    1. using namespace std;
    after your imports
  • You define a function inside the try block. That is not possible in C/C++; but as you have a prototype at the top, you can add it right at the bottom of the code.
  • Instead of defining the check-function in that catch block you probably want to call
    Expand|Select|Wrap|Line Numbers
    1. d.get();
  • You can't throw a class but you can throw an instance of a class. So instead of
    Expand|Select|Wrap|Line Numbers
    1. throw e1;
    you probably want
    Expand|Select|Wrap|Line Numbers
    1. throw new e1;
Btw, please use [CODE] tags when posting code. It makes it much easier to read.

8 1495
Nepomuk
3,112 Expert 2GB
Probably you should show us the code. You could also check this old thread where someone had the same problem. It might help.
Sep 25 '13 #2
weaknessforcats
9,208 Expert Mod 8TB
I remember doing something like that. In my case I used a variable from inside the catch block that was defined in the try block. The try block is out of scope when the catch block starts so the variable was undefined. All I had to do was define the variable outside the try block and everything worked.
Sep 25 '13 #3
Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void check(int ,int,int);
  4. class e1{};
  5. class day
  6. {
  7.     private:
  8.     int date,month,year;
  9.     public:
  10.     void getdata()
  11.     {
  12.         cout<<"Enter date,month,year\n";
  13.         cin>>date>>month>>year;
  14.     }
  15.     void display()
  16.     {
  17.         cout<<date<<"/"<<month<<"/"<<year;
  18.     }
  19.     void get()
  20.     {
  21.         check(date,month,year);
  22.     }
  23. };
  24. void main()
  25. {
  26.     day d;
  27.     d.getdata();
  28.     try
  29.     {
  30.         void check(int d1,int m1,int y1)
  31.         {
  32.             if(d1>31||m1>12||y1>13)
  33.             {
  34.                 throw e1;
  35.             }
  36.         }
  37.     }
  38.     catch(e1)
  39.     {
  40.         cout<<"Invalid";
  41.     }
  42.     d.display();
  43.     getch();
  44. }
Sep 26 '13 #4
Nepomuk
3,112 Expert 2GB
There are a few things wrong with that code, so let's go through them one by one:
  • If you want to use cin and cout without adding the namespace to every call (which would be std::cin and std::cout) you'll have to use that namespace by adding
    Expand|Select|Wrap|Line Numbers
    1. using namespace std;
    after your imports
  • You define a function inside the try block. That is not possible in C/C++; but as you have a prototype at the top, you can add it right at the bottom of the code.
  • Instead of defining the check-function in that catch block you probably want to call
    Expand|Select|Wrap|Line Numbers
    1. d.get();
  • You can't throw a class but you can throw an instance of a class. So instead of
    Expand|Select|Wrap|Line Numbers
    1. throw e1;
    you probably want
    Expand|Select|Wrap|Line Numbers
    1. throw new e1;
Btw, please use [CODE] tags when posting code. It makes it much easier to read.
Sep 26 '13 #5
if i want to code this program in linx environment how should i compile and run this???
Sep 26 '13 #6
thanks alot....I got the output...
Sep 26 '13 #7
Nepomuk
3,112 Expert 2GB
I assume then, that the question of how to compile and run it is answered?
Sep 26 '13 #8
yes... i tried and succeeded
Sep 26 '13 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: pervinder | last post by:
Hi, I have a c++ application which depends on some other libs which uses stlport When i build the application, it works fine on sun/linux/hp platform. (provided the .a for the dependency libs) ...
0
by: John Graat | last post by:
Hi all, I've built the STLport-462 library on AIX-4.3.3 using gcc-3.3.2. No errors during compilation. However, during linking the following error occurs: ld: 0711-317 ERROR: Undefined symbol:...
10
by: eugene | last post by:
I'm trying to compile and run some c++ code to be called from Matlab (mex file) and I'm getting "Invalid MEX-file ... undefined symbol" error. Anybody knows where to look for solution? >>mex...
4
by: r.nikhilk | last post by:
Hi, We are porting C++ applications from 32 bit to 64 bit on AIX platform. (The current version of AIX is 5.3 and xlC verison is 8.0). We are able to compile the applications by including the...
3
by: Kenneth Kahl | last post by:
Hello, I would like to call a C++ programm out of Java with help of JNI. By the followed command I created a "shared library": g++ -shared -o libcalculate.so rechner.cpp When I create an...
8
by: pavan734 | last post by:
Hello, Please excuse me as Iam not posting this to correct group. I have a parser code obtained from flex command. I have many other files. When I compile them Iam getting a message like:...
1
by: yamitmehta | last post by:
When I compile to code using g++arm of VxWorks 5.5 and put it on my board i get the follwing undefined symbols:- Cpool and Csingleton are template classes. CPool has the static member...
1
by: Justin Johnson | last post by:
Hello, I'm trying to build Python 2.5.0 on AIX 5.3 using IBM's compiler (VisualAge C++ Professional / C for AIX Compiler, Version 6). I run configure and make, but makes fails with undefined...
3
by: sdeathstar | last post by:
I am working on IBM AIX machine and using XLC C++ complier version 8.0. 1) Able to compile the objects on AIX from C and C++ source code. 2) Able to create the libraries (combination of C & C++,...
1
by: Michel Esber | last post by:
People, Environment: Linux AS4 I have just installed db2 v9.5 + Fixpak 2 on a machine that has db2 v8 up and running, but I am unable to create and instance: # ./db2icrt -a SERVER -p...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.