9 static const char rcsid[] __attribute__((used)) =
"$Id: Exception.cpp 1664 2016-04-04 03:57:40Z sella $";
11 #include "Exception.h"
12 #include "util/Process.h"
25 #define BUFFER_SIZE 32768
27 using namespace sella;
30 extern bool libutilxx__exception_stacktrace;
33 Exception::Exception(
const char *
function,
const char *file,
int line,
int code)
throw () :
39 if (libutilxx__exception_stacktrace) {
40 using namespace sella::util;
43 stack = Process::stackTrace(Process::getPath());
48 Exception::Exception(
bool sysmsg,
const char *
function,
const char *file,
int line,
int code,
const char *format, ...) throw () :
54 EXCEPTION_BUILDMESSAGE_CODE
56 if (libutilxx__exception_stacktrace) {
57 using namespace sella::util;
60 stack = Process::stackTrace(Process::getPath());
65 Exception::Exception(
const Exception &other)
throw () :
66 function(other.function),
70 message(other.message),
75 Exception::Exception(
const Exception &&other) throw () :
76 function(std::move(other.function)),
77 file(std::move(other.file)),
80 message(std::move(other.message)),
81 stack(std::move(other.stack)),
82 cache(std::move(other.cache))
85 Exception::~Exception() throw () { }
89 this->
function = other.function;
90 this->file = other.file;
91 this->line = other.line;
92 this->code = other.code;
93 this->message = other.message;
94 this->stack = other.stack;
95 this->cache = other.cache;
102 if (
this != &other) {
103 this->
function = std::move(other.function);
104 this->file = std::move(other.file);
105 this->line = other.line;
106 this->code = other.code;
107 this->message = std::move(other.message);
108 this->stack = std::move(other.stack);
109 this->cache = std::move(other.cache);
115 const std::string& Exception::getFunction()
const throw () {
116 return this->
function;
119 const std::string& Exception::getFile()
const throw () {
123 int Exception::getLine()
const throw () {
127 int Exception::getCode()
const throw () {
131 const std::string& Exception::getMessage()
const throw () {
132 return this->message;
135 const char* Exception::what()
const throw () {
136 return this->message.c_str();
139 const std::string& Exception::getStackTrace()
const throw () {
143 const std::string Exception::getName()
const throw () {
144 return std::string(
"sella::Exception");
147 const std::string& Exception::str()
const throw () {
151 snprintf(buf,
sizeof(buf),
":%d]", this->line);
153 cache = (this->message +
" [" + this->file + buf);
159 const char* Exception::c_str()
const throw () {
160 return str().c_str();
163 void Exception::enableStackTrace(
bool on)
throw () {
164 libutilxx__exception_stacktrace = on;
167 void Exception::buildMessage(
bool sysmsg,
const char *format, va_list list)
throw () {
168 char buffer[BUFFER_SIZE] = { 0 };
173 error.append(strerror_r(errno, buffer,
sizeof(buffer)));
176 vsnprintf(buffer,
sizeof(buffer), format, list);
178 this->message = buffer;
179 this->message.append(error);
184 const std::string Exception::demangle(
const char *name)
const throw () {
190 d = abi::__cxa_demangle(name, NULL, NULL, &s);
197 return std::move(res);
199 return std::string(name);