exception.hpp 693 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
/*
 * Copyright (c) 2017 UChicago Argonne, LLC
 *
 * See COPYRIGHT in top-level directory.
 */

#ifndef __THALLIUM_EXCEPTION_HPP
#define __THALLIUM_EXCEPTION_HPP

#include <exception>
#include <sstream>

namespace thallium {

class exception {

    std::string m_msg;

    public:

    template<typename Arg, typename ... Args>
    exception(Arg&& a, Args&&... args) {
        std::stringstream ss;
        ss << std::forward<Arg>(a);
        using expander = int[];
        (void)expander{0, (void(ss << std::forward<Args>(args)),0)...};
        m_msg = ss.str();
    }

    const char* what() const throw ()
    {
        return m_msg.c_str();
    }
};

}

#endif /* end of include guard */