Thread: how to handle exceptions

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    9

    how to handle exceptions

    hi...i m learning the concepts of exception handling and trying to run my first program using try- catch block.
    the problem is the compiler is not able to identify try and catch keywords.
    is there a problem in the compiler or do i have to include any special header file for it.??
    plz guide me...the code is as follows:

    Code:
    #include<iostream.h>
    #include<conio.h>
    void  main()
    { 
      int a,b;
      cin>>a>>b; 
      int x=a-b;
      try
         {  
           if(x!=0) cout<<“Result (a/x)”<<a/x<<“\n”;
           else throw(x); 
         } 
      catch (int i) 
        {
            cout<< “Exception caught”<<i<<“\n”;
        }
       cout<<“End”;
       getch();
    }

  2. #2
    Registered User
    Join Date
    Aug 2006
    Posts
    9
    can nobody help me out..????
    plz do...im stuck....

  3. #3
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    you only waited 10 minutes before bumping your thread! gonna have to have more patience than that

    note, you are using C-style header files.. get rid of the '.h'. and change 'void main' to 'int main'.

    edit: it looks your logic actually works, however your program doesnt compile under a C++ compiler. after you get it to compile, your exception handling will work.
    Last edited by nadroj; 04-22-2007 at 12:14 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with setting text into LTEXT using Window Handle
    By jasperleeabc in forum Windows Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Getting other processes class names
    By Hawkin in forum Windows Programming
    Replies: 3
    Last Post: 03-20-2008, 04:02 PM
  3. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  4. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  5. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM