谢谢!
异常处理!找本c++的书,都应该有介绍!
异常方面的基本知识
C++ primer 说的还可以。
简单的说 就是你可能要抛出某个异常,然后自己选择你想处理的异常
thow 就是扔了 抛出
catch 就是抓 就是你处理相匹配的异常。
try
{
throw
}
catch
属于C++异常处理范畴,参看C++方面著作都有介绍。
<<The c++ programming language>>
最经典的C++百科全书,由C++创始人编写.
抛出异常,扑抓异常
是啊~~~
这个就是C++里面对出现的异常进行抛出\捕捉.
例如:对于捕捉又有这些~~
catch(...)是无法捕捉到异常的类型的
catch(int i)捕捉整数异常
catch(const char*)字符串异常
catch(exception& e)标准异常
例如:
#include <iostream.h>
int main()
{
char *buf;
try
{
buf=new char[512];
if(buf==0)
throw "Memory allocation failure!";
}
catch (char *str)
{
cout << "Exception raised: " << str <<′\n′;
}
//...
return 0;
}
如果buf没有申请到空间,那是Memory allocation failure!呢还是Exception raised: str呢?