#include
template //函数模板
void fun(T n)
{
cout<<"this is fun function\n";
throw n;//抛出异常,返回给调用函数
}
int main(int argc,char **argv)
{
try
{
int n=3;
char *str="hello";
double d=4.5;
float f=3.5;
fun(f);//调用函数模板
}
catch(int m)//只匹配int型
{
cout<<"this is int type\t"<<m<<endl;
}
catch(char *str)
{
cout<<"this is string type\t"<<str<<endl;
}
catch(double d)
{
cout<<"this is double type\t"<<d<<endl;
}
catch(...)//当以上所有类型都不匹配时,才执行这句
{
cout<<"there is no fit"<<endl;
}
return 0;
}