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 ();
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>
299 : x_(x), quoted_(quoted) {}
300 inline bool is_null()
const {
return x_ == NULL;}
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); }
EI(Type const &value)
Construction from given value, that has to bee passed to the catch point.
static internal::ExcStream & val(internal::ExcStream &es)
static internal::ExcStream & qval(internal::ExcStream &es)
static Type const & ref(ExceptionBase const &e)
static Type const * ptr(ExceptionBase const &e)
boost::error_info< Tag, Type > ErrorInfo
Base of exceptions used in Flow123d.
virtual std::string what_type_msg() const
Return type of message ("Program error" for this class). Can be override in descendants.
void print_stacktrace(std::ostream &out) const
Prints formated stacktrace into given stream out.
virtual std::ostringstream & form_message(std::ostringstream &) const
const char * what() const
ExceptionBase()
Default constructor, just calls fill_stacktrace().
StackTrace stack_trace_
Stacktrace of exception.
virtual void print_info(std::ostringstream &out) const =0
std::vector< std::string > frames_to_cut_
Stacktrace frames, which will be cut, see StackTrace::print method.
Class representing stacktrace of exceptions.
ExcStream(std::ostream &stream, const ExceptionBase &exc)
const ExceptionBase & exc_
ExcStream & operator<<(ExcStream &(*pf)(ExcStream &))
const Type & value() const
NullOutputEnvelope(const Type *x, bool quoted=false)
EI_Nested make_nested_ei(Exc &e)
EI_NestedMessage make_nested_message(Exc &e)
#define TYPEDEF_ERR_INFO(EI_Type, Type)
Macro to simplify declaration of error_info types.
static constexpr bool value
internal::ExcStream & operator<<(internal::ExcStream &estream, typename EI< Tag, Type >::template lambda< Func > const &lambda_func)