Add exception_with_delete.cpp

main
p68710245 1 year ago
parent 2638de12ee
commit de0ca8015a

@ -0,0 +1,35 @@
#include <iostream>
#include <string>
#include <memory>
using std::cin, std::cout, std::string;
class A
{
public:
A() { cout << "A构造\n"; }
~A() { cout << "A析构\n"; }
};
class Test
{
std::unique_ptr<A[]> p;
public:
Test()
{
p = std::make_unique<A[]>(3);
throw -1;
}
};
int main()
{
try
{
Test t;
}
catch (int)
{
cout << "捕获了 int异常\n";
}
}
Loading…
Cancel
Save