Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
throwing Copyable versus throwing MoveOnly
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64 #include <exception> #include <stdio.h> #include <typeinfo> struct Copyable { Copyable() { puts(" creating"); } Copyable(const Copyable&) { puts(" copying"); } ~Copyable() { puts(" destroying"); } }; struct MoveOnly { MoveOnly() { puts(" creating"); } MoveOnly(MoveOnly&&) { puts(" moving"); } ~MoveOnly() { puts(" destroying"); } }; using TYPE = Copyable; std::exception_ptr ex; int main() { try { printf("Throwing an exception of type %s...\n", typeid(TYPE).name()); throw TYPE(); } catch (...) { puts("Found the catch block."); puts("Now calling current_exception..."); ex = std::current_exception(); try { puts("Now calling rethrow_exception..."); std::rethrow_exception(ex); } catch (...) { puts("Found the next catch block."); } } puts("Now setting ex to nullptr..."); ex = nullptr; puts("Now exiting main()"); }
run
|
edit
|
history
|
help
0
cv4_template
Removing __unaligned specifier partial solution
<string> Indirect include of <errno.h> with VSC++
#30.2
Program of cube
Wide string conversion with multibyte chars
PTaHHHa
Postfix side effect returning 2
C++ MSVN Compiler Type Check
inherited