C ++ exception handling related

Is divided into bad_cast: a pointer means, such as plastic or the like transfer data type conversion exception
bad_alloc: refers to an aberrant memory allocated time
bad_typeid: null pointer exception of
example:

using namespace std;

int main()
{
	try
	{
		int iy = 1920909109030139 * 2902930290329;
		int* id_ = new int[iy];
	}
	catch (bad_cast &) //转换异常
	{
		cout << "转换异常" << endl;
	}
	catch (bad_alloc &) //内存分配异常
	{
		cout << "内存异常" << endl;
	}
	catch (bad_typeid &)
	{
		cout << "空指针异常" << endl;
	}
    std::cout << "Hello World!\n"; 
}


  • operation result:
    Here Insert Picture Description
Published 382 original articles · won praise 122 · Views 400,000 +

Guess you like

Origin blog.csdn.net/Giser_D/article/details/104447832