Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: s/should_throw/has_error/g;

...

Code Block
bgColor#FFcccc
langcpp
#include <stdexcept>
 
class S {
  bool shouldhas_throwerror() const;
 
public:
  ~S() noexcept(false) {
    // Normal processing
    if (shouldhas_throwerror()) {
      throw std::logic_error("Something bad");
    }
  }
};

...

Code Block
bgColor#FFcccc
langcpp
#include <exception>
#include <stdexcept>
 
class S {
  bool shouldhas_throwerror() const;
 
public:
  ~S() {
    // Normal processing
    if (shouldhas_throwerror() && !std::uncaught_exception()) {
      throw std::logic_error("Something bad");
    }
  }
};

...

Code Block
bgColor#FFcccc
langcpp
#include <stdexcept>
 
class SomeClass {
  class Bad {
    bool shouldhas_throwerror() const;
  public:
    ~Bad() noexcept(false) {
      if (shouldhas_throwerror()) {
        throw std::logic_error("Something bad");
      }
    }
  };

  Bad bad_member;

public:
  ~SomeClass()
  try {
    // ...
  } catch(...) {
    // Attempt to handle exceptions thrown from Bad destructor.
  }
};

...