OpenMiner/include/system/Exception.hpp

40 lines
994 B
C++
Raw Normal View History

2014-12-15 16:47:30 +01:00
/*
* =====================================================================================
*
* Filename: Exception.hpp
*
2018-06-05 01:24:54 +02:00
* Description:
2014-12-15 16:47:30 +01:00
*
* Created: 14/12/2014 05:02:53
*
* Author: Quentin Bazin, <quent42340@gmail.com>
2014-12-15 16:47:30 +01:00
*
* =====================================================================================
*/
#ifndef EXCEPTION_HPP_
#define EXCEPTION_HPP_
#include <exception>
#include <string>
#include "Debug.hpp"
#define EXCEPTION(args...) (Exception(__LINE__, _FILE, args))
2014-12-18 07:02:48 +01:00
class Exception {
2014-12-15 16:47:30 +01:00
public:
template<typename... Args>
Exception(u16 line, std::string filename, Args... args) throw() {
m_errorMsg = Debug::textColor(Debug::TextColor::Red, true) + "at " + filename + ":" + std::to_string(line) + ": " + Debug::textColor(0, true) + Debug::makeString(args...) + Debug::textColor();
2014-12-15 16:47:30 +01:00
}
2018-06-05 01:24:54 +02:00
virtual std::string what() const noexcept {
return m_errorMsg.c_str();
2014-12-15 16:47:30 +01:00
}
2018-06-05 01:24:54 +02:00
2014-12-15 16:47:30 +01:00
private:
std::string m_errorMsg;
};
#endif // EXCEPTION_HPP_