10 #define EXCEPTIONS_HH_
13 #include <boost/exception/all.hpp>
34 #define THROW(whole_exception_expr) BOOST_THROW_EXCEPTION( whole_exception_expr)
55 class ExceptionBase :
public virtual std::exception,
public virtual boost::exception
70 virtual void print_info(std::ostringstream &out)
const=0;
76 virtual const char *
what ()
const throw ();
135 #define DECLARE_EXCEPTION( ExcName, Format) \
136 struct ExcName : public virtual ::ExceptionBase { \
137 virtual void print_info(std::ostringstream &out) const { \
138 using namespace internal; \
139 ::internal::ExcStream estream(out, *this); \
143 virtual ~ExcName() throw () {} \
171 #define TYPEDEF_ERR_INFO(EI_Type, Type) typedef EI< struct EI_Type##_TAG, Type > EI_Type
188 template<
class Tag,
class Type>
189 class EI :
public boost::error_info< Tag, Type > {
191 typedef typename boost::error_info< Tag, Type>
ErrorInfo;
231 template <
class Type>
238 inline const Type &
value()
const {
return (*
x_);}
245 std::ostream&
operator<<
248 if (value.is_null())
return (stream <<
"NO_VALUE");
249 else if (value.is_quoted())
return (stream <<
"'" << value.value() <<
"'");
250 else return (stream << value.value() );
289 template <
class Tag,
class Type,
class Func>
290 internal::ExcStream & operator<<(internal::ExcStream & estream, typename EI<Tag, Type>::template lambda<Func>
const & lambda_func)
307 DECLARE_EXCEPTION( ExcXprintfMsg, << EI_XprintfHeader::val << EI_XprintfMessage::val);
316 template <
class Tag,
class Type>
319 ( ptr(es.
exc_), false );
325 template <
class Tag,
class Type>
328 ( ptr(es.
exc_), true );
333 template <
class Tag,
class Type>
336 Type
const * val_ptr = boost::get_error_info< ErrorInfo > (e);
339 std::cerr <<
"------------------------------------------------------------------------------\n";
340 std::cerr <<
" Fatal Error - dereferencing null pointer when formating an exception message.\n";
341 std::cerr <<
"------------------------------------------------------------------------------\n";
342 std::cerr <<
"** Diagnosting Informations **\n";
343 std::cerr << boost::diagnostic_information_what( e );
350 template <
class Tag,
class Type>
352 {
return boost::get_error_info< ErrorInfo > (e); }
static internal::ExcStream & qval(internal::ExcStream &es)
virtual const char * what() const
ExceptionBase()
Default constructor, just calls fill_stacktrace().
#define DECLARE_EXCEPTION(ExcName, Format)
Macro for simple definition of exceptions.
const ExceptionBase & exc_
void fill_stacktrace()
Call GNU backtrace if available, save call stack information into stacktrace member.
static Type const & ref(ExceptionBase const &e)
static Type const * ptr(ExceptionBase const &e)
static internal::ExcStream & val(internal::ExcStream &es)
#define TYPEDEF_ERR_INFO(EI_Type, Type)
Macro to simplify declaration of error_info types.
EI(Type const &value)
Construction from given value, that has to bee passed to the catch point.
ExcStream & operator<<(ExcStream &(*pf)(ExcStream &))
std::ostream & operator<<(std::ostream &stream, const NullOutputEnvelope< Type > &value)
NullOutputEnvelope(const Type *x, bool quoted=false)
ExcStream(std::ostream &stream, const ExceptionBase &exc)
const Type & value() const
virtual ~ExceptionBase()
Destructor, possibly free stacktrace.
Base of exceptions used in Flow123d.
char ** stacktrace
Array of backtrace frames returned by glibc backtrace_symbols.
void print_stacktrace(std::ostream &out) const
Prints formated stacktrace into given stream out.
boost::error_info< Tag, Type > ErrorInfo
int n_stacktrace_frames
Size of stacktrace table - number of frames.
virtual void print_info(std::ostringstream &out) const =0