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
83 void print_stacktrace(std::ostream &out)
const;
88 virtual void print_info(std::ostringstream &out)
const=0;
94 const char * what ()
const throw ();
100 virtual std::string what_type_msg()
const;
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>
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>
354 internal::ExcStream & operator<<(internal::ExcStream & estream, typename EI<Tag, Type>::template lambda<Func>
const & lambda_func)
371 DECLARE_EXCEPTION( ExcXprintfMsg, << EI_XprintfHeader::val << EI_XprintfMessage::val);
384 template <
class Tag,
class Type>
387 ( ptr(es.
exc_), false );
393 template <
class Tag,
class Type>
396 ( ptr(es.
exc_), true );
401 template <
class Tag,
class Type>
404 Type
const * val_ptr = boost::get_error_info< ErrorInfo > (e);
407 std::cerr <<
"------------------------------------------------------------------------------\n";
408 std::cerr <<
" Fatal Error - dereferencing null pointer when formating an exception message.\n";
409 std::cerr <<
"------------------------------------------------------------------------------\n";
410 std::cerr <<
"** Diagnosting Informations **\n";
411 std::cerr << boost::diagnostic_information_what( e );
418 template <
class Tag,
class Type>
420 {
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