parent
83afdf27bb
commit
2638de12ee
@ -0,0 +1,38 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
using std::cin, std::cout, std::string;
|
||||
|
||||
class A
|
||||
{
|
||||
public:
|
||||
A() { cout << "A构造\n"; }
|
||||
~A() { cout << "A析构\n"; }
|
||||
};
|
||||
|
||||
class Test
|
||||
{
|
||||
A *p;
|
||||
|
||||
public:
|
||||
Test()
|
||||
{
|
||||
p = new A[3];
|
||||
throw -1;
|
||||
}
|
||||
~Test()
|
||||
{
|
||||
delete[] p;
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
try
|
||||
{
|
||||
Test t{};
|
||||
}
|
||||
catch (int)
|
||||
{
|
||||
cout << "捕获了 int异常\n";
|
||||
}
|
||||
}
|
Loading…
Reference in new issue