C++异常处理范例源码
将开发过程中经常用到的一些代码片段做个珍藏,下面代码段是关于C++异常处理范例的代码,希望能对各朋友有较大用。
#include<iostream>
#include<stdio.h>
#include<stdexcept>
using namespace std;
class PathError : public runtime_error
{
public:
{}
};
{
if((in = fopen(argvs[1],"r"))==NULL)
{
}
return in;
}
{
if((out = fopen(argvs[2],"w")) == NULL)
{
}
return out;
}
{
bool flag = 1;
int temp;
while(argc == 3)
{
try
{
in = source( argv );
out = destination( argv );
argc = 0;
}
catch(PathError& PathError)
{
cerr <<"nException occured: " << PathError.what() << endl;
return -1;
}
{
if( temp != EOF)
{
}
}
fclose(in);
fclose(out);
cout<<"nt 1 file copied.n";
flag = 0;
}
if( flag != 0 )
{
cerr<<"nWrong argument list!!!nn";
return -1;
}
return 0;
}