Closed elfring closed 5 years ago
Thank you! I'm fairly new to C++ and here's my opinion on this, so if I'm wrong please kindly give me advice!
I followed Google C++ Style Guide and saw they do not use C++ exceptions, also:
How many details do you find relevant from the three information sources (which I referenced)?
I've been reading Matthew Wilson's article, but I don't dare to say that I understand it completely. I did say that there won't be any thrown exceptions before but now I think I was totally wrong, since I use lots of stuff from STL (for example, std::vector) which can throw std::out_of_index.
I've added a try-catch block in main.cpp which catches const std::exception& ex
. I think this will at least ensure the destructor of WindowManager is called, instead of simply relying on the OS to clean up the mess for us. I've also read that this ensures named pipes/mutex to be cleaned up should the program crashes.
In Matthew Wilson's article, he mentioned that catch (...) is not desirable, since it could catch access violations, divide-by-zero and quench them, (I think this makes it harder to debug), so I decide to catch std::exception only.
Will any aspects get more of your software development attention for a “production-quality main()”?
// 1. Always catch bad_alloc first
catch(std::bad_alloc&)
Hi there!
I've added catch (const std::bad_alloc&)
in ffc0478 (as the first exception to catch).
Also added catch (...)
to avoid uncaught exceptions which ensures stack unwinding occurs.
Thanks for another small source code adjustment.
I expect that exception handling is usually supported by a C++ program. I wonder why your function “main” does not contain corresponding try and catch instructions so far.
How do you think about recommendations by Matthew Wilson in an article?
Would you like to adjust the implementation if you consider effects for uncaught/unhandled exceptions?