|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include "iostream"
- using std::endl;
- using std::cout;
- using std::cin;
- void m_strcpy(char* from,char* to)
- {
- if (from == nullptr)
- {
- throw "源操buf错误";
- }
- if (to == nullptr)
- {
- throw "目标buf错误";
- }
- if (*from == 'A')
- {
- throw "copy过程出错";
- }
- while (*from != '\0')
- {
- *to = *from;
- to++;
- from++;
- }
- *to = '\0';
- }
- void main()
- {
- char buf1[] = "ABCDEFG";
- char buf2[8];
- try
- {
- m_strcpy(buf1, buf2);
- }
- catch (char* e)
- {
- cout << e << "char类型错误" << endl;
- }
-
- cout << buf1 << endl;
- cout << buf2 << endl;
- system("pause");
- }
复制代码
如图 一运行 这里就抛异常 |
|