18 #ifndef EXCEPTIONS_HH_ 19 #define EXCEPTIONS_HH_ 22 #include <boost/exception/all.hpp> 44 #define THROW(whole_exception_expr) BOOST_THROW_EXCEPTION( whole_exception_expr) 66 class ExceptionBase :
public virtual std::exception,
public virtual boost::exception
74 void print_stacktrace(std::ostream &out)
const;
79 virtual void print_info(std::ostringstream &out)
const=0;
85 virtual const char * what ()
const throw ();
91 virtual std::string what_type_msg()
const;
144 #define DECLARE_EXCEPTION( ExcName, Format) \ 145 struct ExcName : public virtual ::ExceptionBase { \ 146 virtual void print_info(std::ostringstream &out) const { \ 147 using namespace internal; \ 148 ::internal::ExcStream estream(out, *this); \ 152 virtual ~ExcName() throw () {} \ 180 #define TYPEDEF_ERR_INFO(EI_Type, Type) typedef EI< struct EI_Type##_TAG, Type > EI_Type 197 template<
class Tag,
class Type>
198 class EI :
public boost::error_info< Tag, Type > {
200 typedef typename boost::error_info< Tag, Type>
ErrorInfo;
203 EI(Type
const & value) : ErrorInfo(value) {}
240 template <
class Type>
244 : x_(x), quoted_(quoted) {}
245 inline bool is_null()
const {
return x_ == NULL;}
247 inline const Type &
value()
const {
return (*x_);}
254 std::ostream&
operator<<
257 if (value.is_null())
return (stream <<
"NO_VALUE");
258 else if (value.is_quoted())
return (stream <<
"'" << value.value() <<
"'");
259 else return (stream << value.value() );
298 template <
class Tag,
class Type,
class Func>
299 internal::ExcStream & operator<<(internal::ExcStream & estream, typename EI<Tag, Type>::template lambda<Func>
const & lambda_func)
316 DECLARE_EXCEPTION( ExcXprintfMsg, << EI_XprintfHeader::val << EI_XprintfMessage::val);
325 template <
class Tag,
class Type>
328 ( ptr(es.
exc_), false );
334 template <
class Tag,
class Type>
337 ( ptr(es.
exc_), true );
342 template <
class Tag,
class Type>
345 Type
const * val_ptr = boost::get_error_info< ErrorInfo > (e);
348 std::cerr <<
"------------------------------------------------------------------------------\n";
349 std::cerr <<
" Fatal Error - dereferencing null pointer when formating an exception message.\n";
350 std::cerr <<
"------------------------------------------------------------------------------\n";
351 std::cerr <<
"** Diagnosting Informations **\n";
352 std::cerr << boost::diagnostic_information_what( e );
359 template <
class Tag,
class Type>
361 {
return boost::get_error_info< ErrorInfo > (e); }
static internal::ExcStream & qval(internal::ExcStream &es)
Class representing stacktrace of exceptions.
StackTrace stack_trace_
Stacktrace of exception.
const ExceptionBase & exc_
#define DECLARE_EXCEPTION(ExcName, Format)
Macro for simple definition of exceptions.
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)
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)
#define TYPEDEF_ERR_INFO(EI_Type, Type)
Macro to simplify declaration of error_info types.
ExcStream(std::ostream &stream, const ExceptionBase &exc)
const Type & value() const
Base of exceptions used in Flow123d.
boost::error_info< Tag, Type > ErrorInfo