Go to the documentation of this file.
18 #ifndef EXCEPTIONS_HH_
19 #define EXCEPTIONS_HH_
23 #include <boost/exception/detail/error_info_impl.hpp>
24 #include <boost/exception/diagnostic_information.hpp>
25 #include <boost/exception/exception.hpp>
26 #include <boost/exception/get_error_info.hpp>
27 #include <boost/throw_exception.hpp>
29 #include <type_traits>
53 #define THROW(whole_exception_expr) BOOST_THROW_EXCEPTION( whole_exception_expr)
75 class ExceptionBase :
public virtual std::exception,
public virtual boost::exception
88 virtual void print_info(std::ostringstream &out)
const=0;
94 const char *
what ()
const throw ();
105 virtual std::ostringstream &
form_message(std::ostringstream &)
const;
158 #define DECLARE_EXCEPTION( ExcName, Format) \
159 struct ExcName : public virtual ::ExceptionBase { \
160 virtual void print_info(std::ostringstream &out) const override { \
161 using namespace internal; \
162 ::internal::ExcStream estream(out, *this); \
166 virtual ~ExcName() throw () {} \
194 #define TYPEDEF_ERR_INFO(EI_Type, Type) typedef EI< struct EI_Type##_TAG, Type > EI_Type
211 template<
class Tag,
class Type>
212 class EI :
public boost::error_info< Tag, Type > {
214 typedef typename boost::error_info< Tag, Type>
ErrorInfo;
275 "Exc must be a descendant of ExceptionBase"
278 return EI_Nested( std::make_shared<Exc>(e) );
286 return EI_NestedMessage( e.what() );
295 template <
class Type>
302 inline const Type &
value()
const {
return (*
x_);}
309 std::ostream&
operator<<
312 if (
value.is_null())
return (stream <<
"NO_VALUE");
313 else if (
value.is_quoted())
return (stream <<
"'" <<
value.value() <<
"'");
314 else return (stream <<
value.value() );
353 template <
class Tag,
class Type,
class Func>
375 template <
class Tag,
class Type>
378 ( ptr(es.
exc_),
false );
384 template <
class Tag,
class Type>
387 ( ptr(es.
exc_),
true );
392 template <
class Tag,
class Type>
395 Type
const * val_ptr = boost::get_error_info< ErrorInfo > (e);
398 std::cerr <<
"------------------------------------------------------------------------------\n";
399 std::cerr <<
" Fatal Error - dereferencing null pointer when formating an exception message.\n";
400 std::cerr <<
"------------------------------------------------------------------------------\n";
401 std::cerr <<
"** Diagnosting Informations **\n";
402 std::cerr << boost::diagnostic_information_what( e );
409 template <
class Tag,
class Type>
411 {
return boost::get_error_info< ErrorInfo > (e); }
static const Type & ref(ExceptionBase const &e)
static internal::ExcStream & qval(internal::ExcStream &es)
boost::error_info< Tag, Type > ErrorInfo
virtual std::ostringstream & form_message(std::ostringstream &) const
Base of exceptions used in Flow123d.
ExcStream(std::ostream &stream, const ExceptionBase &exc)
ExceptionBase()
Default constructor, just calls fill_stacktrace().
static constexpr bool value
EI_Nested make_nested_ei(Exc &e)
StackTrace stack_trace_
Stacktrace of exception.
const ExceptionBase & exc_
std::ostream & operator<<(std::ostream &stream, const NullOutputEnvelope< Type > &value)
Class representing stacktrace of exceptions.
const Type & value() const
virtual void print_info(std::ostringstream &out) const =0
ExcStream & operator<<(ExcStream &(*pf)(ExcStream &))
std::vector< std::string > frames_to_cut_
Stacktrace frames, which will be cut, see StackTrace::print method.
NullOutputEnvelope(const Type *x, bool quoted=false)
static const Type * ptr(ExceptionBase const &e)
virtual std::string what_type_msg() const
Return type of message ("Program error" for this class). Can be override in descendants.
#define TYPEDEF_ERR_INFO(EI_Type, Type)
Macro to simplify declaration of error_info types.
EI_NestedMessage make_nested_message(Exc &e)
const char * what() const
EI(Type const &value)
Construction from given value, that has to bee passed to the catch point.
virtual ~ExceptionBase()
Destructor, possibly free stacktrace.
void print_stacktrace(std::ostream &out) const
Prints formated stacktrace into given stream out.
static internal::ExcStream & val(internal::ExcStream &es)