I searched the Internet and found a lot of articles about this topic. However, I found there is no complete checklist to verify our code's quality of exception-safety.

So, I want to collect valuable best practices for C++ exception handling from you.

I first list some practices of my own:

  1. Catch all exceptions if any in destructors:

    struct A
    {
        ~A()
        {
            try
            {
                // Here may throw exceptions
            }
            catch (std::runtime_error& e)
            {}
            catch (...)
            {
                logging("...");
            }
        }
    };
    
  2. Add function name, source file name and line numer in exception information. __func__, __FILE__ and __LINE__ are good friends.

  3. Never use exception specifications. The reason is given in the book "C++ Coding Standards".

What are yours?

Edit
Report