#include <iostream>
#include <cstdlib>
using namespace std;
class stu
{
public:
template <class T>
class error
{
};
stu(int num)
{
if (num<0)
{
throw error<int>();
}
else if (num>60)
{
throw error<double>();
}
i = num;
n = new int[i];
}
~stu()
{
delete[] n;
}
private:
int i;
int *n;
};
void main()
{
try
{
stu s(-6);
}
catch (stu::error<int> e)
{
cout << "iefsfhs" << endl;
cout<<typeid(e).name() << endl;
}
catch (...)
{
cout << "上面的异常类型不匹配" << endl;
}
system("pause");
}
模板中含有类的异常的捕获
最新推荐文章于 2024-05-02 18:14:48 发布