Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

i have the following program using exception handling.

#include<iostream.h>
#include<conio.h>

void divide(int x,int y,int z)
{
  cout<<"
 Inside function 1 
";

  if((x-y)!=0)
  {
    int R=z/(x-y);
    cout << "Result =" << R<<"
";
  } // end of if
  else
  {
    throw(x-y);
  }  // end of else
}   // end of void

int main()
{
  try
  {
    cout<< "Inside try block
";
    divide(10,20,30);
    divide(10,10,20);
  } //end of try
  catch(int i)
  {
    cout<< "Caught
";
  }
  return 0;
} //end of main

When compiling i get the following errors

Function throw should have a prototype.

Undefined symbol "try"

Statement missing ;

Function should return a value.

Please help me.Thanks a lot

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
241 views
Welcome To Ask or Share your Answers For Others

1 Answer

Compile with some non-ancient C++ compiler, use #include <iostream> instead of #include <iostream.h>, and drop #include <conio.h>, then it should just work once you have using std::cout;


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...