etk/etk-core/Exception.cpp

79 lines
1.3 KiB
C++
Raw Normal View History

2017-09-26 09:31:47 +02:00
/**
* @author Edouard DUPIN
* @copyright 2017, Edouard DUPIN, all right reserved
* @license MPL-2 (see license file)
*/
#include <etk/Exception.hpp>
#include <etk/String.hpp>
etk::Exception::Exception():
2018-06-22 22:47:41 +02:00
m_type("UNKNOW") {
2017-09-26 09:31:47 +02:00
}
2018-06-22 22:47:41 +02:00
etk::Exception::Exception(const char* _type, const etk::String& _what):
2017-09-26 09:31:47 +02:00
m_type(_type),
2018-06-22 22:47:41 +02:00
m_what(_what) {
2017-09-26 09:31:47 +02:00
}
2018-07-16 21:23:28 +02:00
etk::Exception::Exception(const etk::String& _what):
m_type("ETK_EXCEPTION"),
m_what(_what) {
}
2017-09-26 09:31:47 +02:00
const char* etk::Exception::which() const {
return m_type;
}
const etk::String etk::Exception::what() const {
return m_what;
}
2018-06-22 22:47:41 +02:00
const char* etk::Exception::file() const {
return m_file;
}
size_t etk::Exception::line() const {
return m_line;
}
const char* etk::Exception::function() const {
2017-09-26 09:31:47 +02:00
return m_function;
}
2018-06-22 22:47:41 +02:00
etk::Exception& etk::Exception::setFile(const char* _value) {
m_file = _value;
return *this;
}
etk::Exception& etk::Exception::setLine(size_t _value) {
m_line = _value;
return *this;
}
etk::Exception& etk::Exception::setFunction(const char* _value) {
m_function = _value;
return *this;
}
2017-09-26 09:31:47 +02:00
etk::String etk::Exception::toString() const {
etk::String out = "exception{";
out += m_type;
out += ":";
out += m_what;
if (m_function != null) {
2018-06-22 22:47:41 +02:00
out += " on ";
2017-09-26 09:31:47 +02:00
out += m_function;
}
2018-06-22 22:47:41 +02:00
if (m_file != null) {
out += " in ";
out += m_file;
out += ":";
out += m_line;
}
2017-09-26 09:31:47 +02:00
out += "}";
return out;
}