Try/catch undefined

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • divyajoshi12
    New Member
    • Dec 2011
    • 1

    Try/catch undefined

    Hey friends,
    I coded this program in c++ with that blue window background software(I don't know its version) that i usually use. I save this program as excepp.cpp and got 4 errors : Undedined symbol: try and undefined symbol : throw , Statement missing ; and statement missing ; .

    Code:
    #include<iostream.h>
    #include<conio.h>
    class ex
    {
    };
    class ex1: public ex
    {
    };
    
    class sample
    {
    	public:
    		void fun()
    		{
    			throw ex1();
    		}
    };
    
    void main()
    {
    try
    {
    	sample s;
    	s.fun();
    }
    catch(ex e1)
    {
    cout<<"ex exception";
    }
    catch(ex1 e)
    {
    cout<<"EX! exception";
    }
    getch();
    }
    Thanks in advance :-)
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You are using iostream.h which os pre-ANSI C++ from 1998 or earlier. If memory serves, exception handling was not implemented in those years.

    Get a newer compiler. One thst uses <iostream>.

    Also, main() returns an int and not void.

    Comment

    Working...