From de0ca8015a631a1bc31aa39608ab838d70242fc4 Mon Sep 17 00:00:00 2001 From: p68710245 Date: Sat, 11 May 2024 11:40:55 +0800 Subject: [PATCH] Add exception_with_delete.cpp --- exception_with_delete.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 exception_with_delete.cpp diff --git a/exception_with_delete.cpp b/exception_with_delete.cpp new file mode 100644 index 0000000..4f9b773 --- /dev/null +++ b/exception_with_delete.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +using std::cin, std::cout, std::string; + +class A +{ +public: + A() { cout << "A构造\n"; } + ~A() { cout << "A析构\n"; } +}; + +class Test +{ + std::unique_ptr p; + +public: + Test() + { + p = std::make_unique(3); + throw -1; + } +}; + +int main() +{ + try + { + Test t; + } + catch (int) + { + cout << "捕获了 int异常\n"; + } +} \ No newline at end of file