我有以下使用异常处理的程序。
#include<iostream.h>
#include<conio.h>
void divide(int x,int y,int z)
{
cout<<"\n Inside function 1 \n";
if((x-y)!=0)
{
int R=z/(x-y);
cout << "Result =" << R<<"\n";
} // end of if
else
{
throw(x-y);
} // end of else
} // end of void
int main()
{
try
{
cout<< "Inside try block\n";
divide(10,20,30);
divide(10,10,20);
} //end of try
catch(int i)
{
cout<< "Caught\n";
}
return 0;
} //end of main
编译时出现如下错误
Function throw should have a prototype.
Undefined symbol "try"
Statement missing ;
Function should return a value.
请帮助我,非常感谢
最佳答案
用一些非古老的 C++ 编译器编译,使用 #include <iostream>
而不是 #include <iostream.h>
, 然后放下 #include <conio.h>
, 那么一旦你有了 using std::cout;
它就应该工作了
关于c++ - C++中的异常处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3644976/