4 Ocak 2018 Perşembe

std::uncaught_exceptions

Giriş
C++17 ile geliyor. Açıklaması şöyle.
It allows you to know if an object is being destroyed due to stack unwinding or through normal execution. This lets you know if you should do different kinds of cleanup. Consider a RAII object that will rollback a transaction if it is destroyed due to stack unwinding.
Örnek
Şöyle yaparız.
#include <iostream>

using namespace std;

struct A
{
  ~A()
  {
    cout << std::uncaught_exceptions() << endl;
  }
};

int main()
{
  try
  {
    try
    {

      A a1;
      throw 1;
    }
    catch (...)
    {
      A a2;
      throw;
    }
  }
  catch (...)
  {
    A a3;
  }   
}

Hiç yorum yok:

Yorum Gönder