#include <iostream>
#include <sstream>

using namespace std;

class ScopeGuard
{
    bool commited;
    stringstream accumulator;
public:
    ScopeGuard() : commited(false) {}
    void commit()
    {
        commited = true;
    }
    bool done() const
    {
        return commited;
    }
    template<typename Data>
    ScopeGuard &operator<<(const Data &x)
    {
        accumulator << x;
        return *this;
    }
    ~ScopeGuard()
    {
        if(commited)
            cout << accumulator.str();
    }
};

#define LOG(anything) \
for(ScopeGuard guard; !guard.done(); guard.commit()) \
    guard \
/**/
 

int main()
{
    try
    {
        LOG(lg) << "Failure" << (false ? "\n" : throw 1);
    }
    catch(...) {}

    LOG(lg) << "Success" << (true ? "\n" : throw 1);
}