mirror of
https://github.com/jakcron/nstool
synced 2024-11-22 21:49:30 +00:00
[fnd] Changed internal behavior of fnd::Exception.
This commit is contained in:
parent
6531b1083e
commit
076fba9bcb
3 changed files with 17 additions and 38 deletions
|
@ -5,7 +5,7 @@ using namespace fnd;
|
||||||
Exception::Exception() noexcept :
|
Exception::Exception() noexcept :
|
||||||
what_(""),
|
what_(""),
|
||||||
module_(""),
|
module_(""),
|
||||||
level_(E_FATAL)
|
error_("")
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,33 +13,23 @@ Exception::Exception() noexcept :
|
||||||
Exception::Exception(const std::string & what) noexcept :
|
Exception::Exception(const std::string & what) noexcept :
|
||||||
what_(what),
|
what_(what),
|
||||||
module_(""),
|
module_(""),
|
||||||
level_(E_FATAL)
|
error_(what)
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Exception::Exception(const std::string & what, ExceptionLevel level) noexcept :
|
|
||||||
what_(what),
|
|
||||||
module_(""),
|
|
||||||
level_(level)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Exception::Exception(const std::string & module, const std::string & what) noexcept :
|
Exception::Exception(const std::string & module, const std::string & what) noexcept :
|
||||||
what_(what),
|
what_(""),
|
||||||
module_(module),
|
module_(module),
|
||||||
level_(E_FATAL)
|
error_(what)
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Exception::Exception(const std::string & module, const std::string & what, ExceptionLevel level) noexcept :
|
|
||||||
what_(what),
|
|
||||||
module_(module),
|
|
||||||
level_(level)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Exception::~Exception()
|
|
||||||
{
|
{
|
||||||
|
if (module_.length() > 0)
|
||||||
|
{
|
||||||
|
what_ = "[" + module_ + " ERROR] " + error_;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
what_ = error_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* Exception::what() const noexcept
|
const char* Exception::what() const noexcept
|
||||||
|
@ -52,7 +42,7 @@ const char* Exception::module() const noexcept
|
||||||
return module_.c_str();
|
return module_.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Exception::is_fatal() const noexcept
|
const char * fnd::Exception::error() const noexcept
|
||||||
{
|
{
|
||||||
return level_ == E_FATAL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,28 +7,17 @@ namespace fnd
|
||||||
class Exception : public std::exception
|
class Exception : public std::exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum ExceptionLevel
|
|
||||||
{
|
|
||||||
E_RECOVERABLE,
|
|
||||||
E_FATAL,
|
|
||||||
};
|
|
||||||
|
|
||||||
Exception() noexcept;
|
Exception() noexcept;
|
||||||
Exception(const std::string& what) noexcept;
|
Exception(const std::string& what) noexcept;
|
||||||
Exception(const std::string& what, ExceptionLevel level) noexcept;
|
|
||||||
Exception(const std::string& module, const std::string& what) noexcept;
|
Exception(const std::string& module, const std::string& what) noexcept;
|
||||||
Exception(const std::string& module, const std::string& what, ExceptionLevel level) noexcept;
|
|
||||||
|
|
||||||
|
|
||||||
~Exception();
|
|
||||||
|
|
||||||
const char* what() const noexcept;
|
const char* what() const noexcept;
|
||||||
const char* module() const noexcept;
|
const char* module() const noexcept;
|
||||||
bool is_fatal() const noexcept;
|
const char* error() const noexcept;
|
||||||
private:
|
private:
|
||||||
std::string what_;
|
std::string what_;
|
||||||
std::string module_;
|
std::string module_;
|
||||||
ExceptionLevel level_;
|
std::string error_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
} catch (const fnd::Exception& e)
|
} catch (const fnd::Exception& e)
|
||||||
{
|
{
|
||||||
printf("[%s%sERROR] %s\n", e.module(), strlen(e.module()) > 0 ? " " : "", e.what());
|
printf("%s\n",e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue