From: Christian Herdtweck Date: Tue, 4 Sep 2018 09:29:07 +0000 (+0200) Subject: Realized that SouceLocation and ScopeTracker can never be no-throw X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=b50d8b1d5e9cded2da76dec5f926bc1cb5a7c4c6;p=libi2ncommon Realized that SouceLocation and ScopeTracker can never be no-throw Constructors can always throw if the class has non-pointer attributes (at least I think so). So would have to re-design SourceLocation and ScopeTracker to only contain pointers in order to make SCOPETRACKER guaranteed no-throw. --- diff --git a/src/source_track_basics.cpp b/src/source_track_basics.cpp index 9f8f470..4985570 100644 --- a/src/source_track_basics.cpp +++ b/src/source_track_basics.cpp @@ -35,23 +35,48 @@ namespace I2n /* ** implementation of SourceLocation + * + * Failed to really make this no-throw. Even in this form, class attributes File and FunctionName need to have + * some value which takes up memory space, so PCLINT rightly complains that exception '...' thrown from string + * construction is not on throw-list. + * + * To really guarantee a no-throw constructor, would have to only have pointers that can be set to NULL if + * something fails. */ SourceLocation::SourceLocation() throw () -: Line ( 0 ) { + try + { + File = ""; + Line = 0; + FunctionName = ""; + LocationTag = ""; + } + catch(...) + { + ; // do nothing + } } // eo SourceLocation::SourceLocation() SourceLocation::SourceLocation ( const std::string& file, - long line, + const long& line, const std::string& funcname ) throw () -: File( file ) -, Line( line ) -, FunctionName( funcname ) { + try + { + File = file; + Line = line; + FunctionName = funcname; + LocationTag = ""; + } + catch(...) + { + ; // do nothing + } } // eo SourceLocation::SourceLocation(const std::string&,long,const std::string&) diff --git a/src/source_track_basics.hpp b/src/source_track_basics.hpp index ad18cb8..0946ab2 100644 --- a/src/source_track_basics.hpp +++ b/src/source_track_basics.hpp @@ -56,17 +56,17 @@ struct SourceLocation SourceLocation( const std::string& file, - long line, + const long& line, const std::string& funcname) throw (); - operator bool() const throw () + operator bool() const { return Line>0 and not File.empty() and not FunctionName.empty(); } // eo operator bool - std::string get_function_name() const throw () { return FunctionName; } - std::string get_filename() const throw () { return File; } - long get_line_number() const throw () { return Line; } + std::string get_function_name() const { return FunctionName; } + std::string get_filename() const { return File; } + long get_line_number() const { return Line; } std::string get_location_tag() const; diff --git a/src/tracefunc.hpp b/src/tracefunc.hpp index 36a6227..cf5475e 100644 --- a/src/tracefunc.hpp +++ b/src/tracefunc.hpp @@ -45,8 +45,7 @@ class PerThreadContainer; * basically: emits a ENTER message on construction and a LEAVE message on destruction. * And indent these messages acoording to the nesting depth. * - * If something goes wrong nothing is thrown from constructor/destructor. Will try to - * log only that some problem occurred. + * Tried to avoid any throw from constructor/destructor but failed */ class ScopeTracker { @@ -75,6 +74,8 @@ class ScopeTracker /** * @brief constructs a scope tracker. + * + * Would have like to make this guaranteed no-throw, but failed. */ #define SCOPETRACKER() ::I2n::Tracer::ScopeTracker __scope_tracker(HERE)