18 #ifndef EXCEPTIONS_HH_ 19 #define EXCEPTIONS_HH_ 22 #include <boost/exception/all.hpp> 45 #define THROW(whole_exception_expr) BOOST_THROW_EXCEPTION( whole_exception_expr) 67 class ExceptionBase :
public virtual std::exception,
public virtual boost::exception
75 void print_stacktrace(std::ostream &out)
const;
80 virtual void print_info(std::ostringstream &out)
const=0;
86 const char * what ()
const throw ();
92 virtual std::string what_type_msg()
const;
97 virtual std::ostringstream &form_message(std::ostringstream &)
const;
150 #define DECLARE_EXCEPTION( ExcName, Format) \ 151 struct ExcName : public virtual ::ExceptionBase { \ 152 virtual void print_info(std::ostringstream &out) const override { \ 153 using namespace internal; \ 154 ::internal::ExcStream estream(out, *this); \ 158 virtual ~ExcName() throw () {} \ 186 #define TYPEDEF_ERR_INFO(EI_Type, Type) typedef EI< struct EI_Type##_TAG, Type > EI_Type 203 template<
class Tag,
class Type>
204 class EI :
public boost::error_info< Tag, Type > {
206 typedef typename boost::error_info< Tag, Type>
ErrorInfo;
267 "Exc must be a descendant of ExceptionBase" 270 return EI_Nested( std::make_shared<Exc>(e) );
278 return EI_NestedMessage( e.what() );
287 template <
class Type>
291 : x_(x), quoted_(quoted) {}
292 inline bool is_null()
const {
return x_ == NULL;}
294 inline const Type &
value()
const {
return (*x_);}
301 std::ostream&
operator<<
304 if (
value.is_null())
return (stream <<
"NO_VALUE");
305 else if (
value.is_quoted())
return (stream <<
"'" <<
value.value() <<
"'");
306 else return (stream <<
value.value() );
345 template <
class Tag,
class Type,
class Func>
346 internal::ExcStream & operator<<(internal::ExcStream & estream, typename EI<Tag, Type>::template lambda<Func>
const & lambda_func)
363 DECLARE_EXCEPTION( ExcXprintfMsg, << EI_XprintfHeader::val << EI_XprintfMessage::val);
376 template <
class Tag,
class Type>
379 ( ptr(es.
exc_), false );
385 template <
class Tag,
class Type>
388 ( ptr(es.
exc_), true );
393 template <
class Tag,
class Type>
396 Type
const * val_ptr = boost::get_error_info< ErrorInfo > (e);
399 std::cerr <<
"------------------------------------------------------------------------------\n";
400 std::cerr <<
" Fatal Error - dereferencing null pointer when formating an exception message.\n";
401 std::cerr <<
"------------------------------------------------------------------------------\n";
402 std::cerr <<
"** Diagnosting Informations **\n";
403 std::cerr << boost::diagnostic_information_what( e );
410 template <
class Tag,
class Type>
412 {
return boost::get_error_info< ErrorInfo > (e); }
static internal::ExcStream & qval(internal::ExcStream &es)
Class representing stacktrace of exceptions.
#define DECLARE_EXCEPTION(ExcName, Format)
Macro for simple definition of exceptions.
StackTrace stack_trace_
Stacktrace of exception.
const ExceptionBase & exc_
EI_NestedMessage make_nested_message(Exc &e)
static constexpr bool value
static Type const & ref(ExceptionBase const &e)
std::vector< std::string > frames_to_cut_
Stacktrace frames, which will be cut, see StackTrace::print method.
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
Base of exceptions used in Flow123d.
EI_Nested make_nested_ei(Exc &e)
boost::error_info< Tag, Type > ErrorInfo