Disable backtrace generation in Hurricane::Error constructor.

* Change: In Hurricane::Backtrace constructor, add a boolean parameter
    to enable/disable the actual backtrace generation.
* Change: In Hurricane::Error constructor, disable by default the
    backtrace generation. The backtrace is useful when the Error is
    thrown, and the program therefore stopped. But in many case we
    just issue the error message on the console and try to continue.
    But if the backtrace is enabled, it terribly slow down the
    program.
      Have to think about an clean way to re-enable the trace only
    when the exception is thrown.
This commit is contained in:
Jean-Paul Chaput 2018-01-06 15:13:20 +01:00
parent 24d8fe5957
commit 864b031b6a
3 changed files with 8 additions and 6 deletions

View File

@ -427,9 +427,11 @@ namespace Hurricane {
// 3 libstdc++.6.dylib 0x9142514b _ZSt9terminatev + 29
Backtrace::Backtrace ()
Backtrace::Backtrace ( bool enabled )
: _stack()
{
if (not enabled) return;
if (_inConstructor) {
_stack.push_back( "[BUG] Backtrace::Backtrace(): An error occurred in the backtace *istself*." );
_stack.push_back( "" );

View File

@ -47,7 +47,7 @@ namespace Hurricane {
: Exception ()
, _reason (reason)
, _code (0)
, _backtrace()
, _backtrace(false)
{ }
@ -55,7 +55,7 @@ namespace Hurricane {
: Exception ()
, _reason (reason)
, _code (code)
, _backtrace()
, _backtrace(false)
{ }
@ -63,7 +63,7 @@ namespace Hurricane {
: Exception ()
, _reason ()
, _code (0)
, _backtrace()
, _backtrace(false)
{
static char formatted [ 8192 ];
va_list args;
@ -80,7 +80,7 @@ namespace Hurricane {
: Exception ()
, _reason ()
, _code (code)
, _backtrace()
, _backtrace(false)
{
static char formatted [ 8192 ];
va_list args;

View File

@ -42,7 +42,7 @@ namespace Hurricane {
class Backtrace {
public:
Backtrace ();
Backtrace ( bool enabled );
~Backtrace ();
inline std::string where () const;
inline std::string textWhere () const;