|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include "iostream"
- using std::endl;
- using std::cout;
- using std::cin;
- class BadSrcType{};
- class BadDestType{};
- class BadProcessType
- {
- public:
- BadProcessType()
- {
- cout << "BadProcessType构造执行了\n";
- }
- BadProcessType(const BadProcessType& bp)
- {
- cout << "BadProcessType copy 构造执行了\n";
- }
- ~BadProcessType()
- {
- cout << "~BadProcessType析构执行了\n";
- }
- };
- void my_strcpy(char* from, char* to)
- {
- if (from == nullptr)
- {
- throw BadSrcType();
- }
- if (to == nullptr)
- {
- throw BadDestType();
- }
- if (*from == 'a')
- {
- throw BadProcessType();
- }
- if (*from == 'b')
- {
- throw& (BadProcessType());
- }
- }
- void main()
- {
- char buf1[] = "bacdefg";
- char buf2[8];
- try
- {
- my_strcpy(buf1, buf2);
- }
- catch (BadProcessType e) //问题1:当这个catch捕捉到异常的时候 为啥catch运行完了 异常对象和e对象都析构?
- {
- cout << "BadProcessTypece类型错误\n";
- }
- catch (BadProcessType * e)//问题2:为啥在这个catch捕捉到异常之前 异常对象已经析构了?
- {
- cout << "BadProcessTypece*类型错误\n";
- }
- system("pause");
- }
复制代码 |
|