Commit 480782bd authored by Sebastien Ponce's avatar Sebastien Ponce
Browse files

Added the possibility to fake the backtrace in CASTOR Exceptions to have...

Added the possibility to fake the backtrace in CASTOR Exceptions to have lightweight ones. Used it for the NoEntry exception
parent 651ba1a1
......@@ -118,7 +118,8 @@ namespace castor {
}
#endif // COLLECTEXTRABACKTRACEINFOS
castor::exception::Backtrace::Backtrace(): m_trace() {
castor::exception::Backtrace::Backtrace(bool fake): m_trace() {
if (fake) return;
void * array[200];
g_lock.lock();
size_t depth = ::backtrace(array, sizeof(array)/sizeof(void*));
......
......@@ -28,7 +28,7 @@ namespace castor {
namespace exception {
class Backtrace {
public:
Backtrace();
Backtrace(bool fake=false);
operator std::string() const { return m_trace; }
Backtrace& operator= (const Backtrace& bt) { m_trace = bt.m_trace; return *this; }
private:
......
......@@ -29,14 +29,14 @@
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
castor::exception::Exception::Exception(int se, std::string context) :
m_message(context), m_serrno(se){}
castor::exception::Exception::Exception(int se, std::string context, bool embedBacktrace) :
m_message(context), m_serrno(se), m_backtrace(!embedBacktrace) {}
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
castor::exception::Exception::Exception(std::string context) :
m_message(context), m_serrno(SEINTERNAL){}
castor::exception::Exception::Exception(std::string context, bool embedBacktrace) :
m_message(context), m_serrno(SEINTERNAL), m_backtrace(!embedBacktrace) {}
//------------------------------------------------------------------------------
// copy constructor
......
......@@ -46,15 +46,19 @@ namespace castor {
* @param serrno the serrno code of the corresponding C error
* @param context optional context string added to the message
* at initialisation time.
* @param embedBacktrace whether to embed a backtrace of where the
* exception was throw in the message
*/
Exception(int se, std::string context="");
Exception(int se, std::string context="", bool embedBacktrace=true);
/**
* Empty Constructor with implicit serrno = SEINERNAL;
* @param context optional context string added to the message
* at initialisation time.
* @param embedBacktrace whether to embed a backtrace of where the
* exception was throw in the message
*/
Exception(std::string context="");
Exception(std::string context="", bool embedBacktrace=true);
/**
* Copy Constructor
......
......@@ -31,4 +31,5 @@
// Constructor
// -----------------------------------------------------------------------
castor::exception::NoEntry::NoEntry() :
castor::exception::Exception(ENOENT) {}
// No backtrace for this exception
castor::exception::Exception(ENOENT, "", false) {}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment