Thread: Exception handling

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    38
    This was my solution
    but i don't know how can i detect an overflow??

    Code:
    #include <iostream.h>
    
    int main(){
    	
        int x;
        int eof = 0;
        int sum = 0;
    
        cout<<"Enter a list of integers in the range of -100 to 100 (0 to end):"<<endl;
        cin>>x;
    	
          try{
            if(x<-100 || x>100)
              throw x;
            sum = x*x;}
          catch(int e){
            cout<<e<<" is out of range"<<endl;}
    
          while(x != eof){
            cin>>x;
            try{
              if(x<-100 || x>100)
                throw x;
              sum = sum+(x*x);}
            catch(int e){
              cout<<e<<" is out of range"<<endl;}
    	}
    	
           cout<<"sum of the input squares = "<<sum<<endl;
           return 0;}
    Last edited by kuwait; 12-11-2003 at 05:15 AM.
    please set free our POWs

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. signal handling and exception handling
    By lehe in forum C++ Programming
    Replies: 2
    Last Post: 06-15-2009, 10:01 PM
  2. Exception handling in a large project
    By EVOEx in forum C++ Programming
    Replies: 7
    Last Post: 01-25-2009, 07:33 AM
  3. exception handling
    By coletek in forum C++ Programming
    Replies: 2
    Last Post: 01-12-2009, 05:28 PM
  4. is such exception handling approach good?
    By George2 in forum C++ Programming
    Replies: 8
    Last Post: 12-27-2007, 08:54 AM
  5. Signal and exception handling
    By nts in forum C++ Programming
    Replies: 23
    Last Post: 11-15-2007, 02:36 PM