Flow123d  JS_before_hm-1804-gf2ad740aa
Classes | Macros
Exceptions

Classes

class  Input::Exception
 Base of exceptions due to user input. More...
 
class  ExceptionBase
 Base of exceptions used in Flow123d. More...
 
class  StackTrace
 Class representing stacktrace of exceptions. More...
 

Macros

#define DECLARE_INPUT_EXCEPTION(ExcName, Format)
 Macro for simple definition of input exceptions. More...
 
#define THROW(whole_exception_expr)   BOOST_THROW_EXCEPTION( whole_exception_expr)
 Wrapper for throw. Saves the throwing point. More...
 
#define DECLARE_EXCEPTION(ExcName, Format)
 Macro for simple definition of exceptions. More...
 
#define TYPEDEF_ERR_INFO(EI_Type, Type)   typedef EI< struct EI_Type##_TAG, Type > EI_Type
 Macro to simplify declaration of error_info types. More...
 

Detailed Description

Macro Definition Documentation

◆ DECLARE_EXCEPTION

#define DECLARE_EXCEPTION (   ExcName,
  Format 
)
Value:
struct ExcName : public virtual ::ExceptionBase { \
virtual void print_info(std::ostringstream &out) const override { \
using namespace internal; \
::internal::ExcStream estream(out, *this); \
estream Format ; \
out << std::endl; \
} \
virtual ~ExcName() throw () {} \
}

Macro for simple definition of exceptions.

First parameter, ExcName, is name of the exception class to define. Macro expands to the class derived from ExceptionBase and implements virtual method print_info with output given by Format, the second parameter of the macro. This method is used by what() method to produce specific part of the error message.

You can use error info classes (see TYPEDEFERR_INFO) and stream modifiers val, qval to output relevant data. Modifier val outputs plain value, modifier qval outputs value in quotas.

Example:

TYPEDEF_ERR_INFO( EI_Dim1Mismatch, int);
TYPEDEF_ERR_INFO( EI_Dim2Mismatch, int);
DECLARE_EXCEPTION( ExcDimensionMismatch,
<< "Dimensions dim1=" << EI_Dim1Missmatch::val
<< " and dim2=" << EI_Dim2Mismatch::val << " should be same.");

One can also pass whole classes through the exception as long as they are default constructable and copy constructable.

Example:

class Matrix;
TYPEDEF_ERR_INFO( EI_Matrix, Matrix);
DECLARE_EXCEPTION( ExcWrongMatrixState,
<< "Matrix state: " << EI_Matrix::ptr(*this)->state() << "\n"
<< "Matrix info: " << EI_Matrix::ref(*this).info() );

The example shows two ways how to call methods of the object of class Matrix passed through the exception. One can either get pointer to the object or reference. The ref method checks that the pointer to the object is not NULL (so that the object was actually passed). The ptr method do not perform the check. However, when using one of these methods you have to guarantee that the error_info object is passed to the exception at every throw point that use that exception. Otherwise you get an error, meaningful in case of the ref method, seg. fault for the ptr method.

Currently implemented mechanism do no support standard stream modifiers, namely "endl". Please, use "\n" instead.

Definition at line 158 of file exceptions.hh.

◆ DECLARE_INPUT_EXCEPTION

#define DECLARE_INPUT_EXCEPTION (   ExcName,
  Format 
)
Value:
struct ExcName : public virtual ::Input::Exception { \
virtual void print_info(std::ostringstream &out) const { \
using namespace internal; \
::internal::ExcStream estream(out, *this); \
estream Format \
<< "\nAt input address: " \
<< ::Input::EI_Address::val; \
out << std::endl; \
} \
virtual ~ExcName() throw () {} \
}

Macro for simple definition of input exceptions.

Works in the same way as DECLARE_EXCEPTION, just define class derived from InputException. Meant to be used for exceptions due to wrong input from user.

Reports input address provided through EI_Address object, see above.

Definition at line 69 of file input_exception.hh.

◆ THROW

#define THROW (   whole_exception_expr)    BOOST_THROW_EXCEPTION( whole_exception_expr)

Wrapper for throw. Saves the throwing point.

Macro for throwing with saving place of the throw. Just shortcut for BOOST_THROW_EXCEPTION. Creates boost kind of exception, that may accept further information through redirection.

Usage:

THROW( ExcError() << EI_SomeValue(42) );

EI_SomeValue is an error_info object for transfer of values form throw point to catch point. See EI<Tag,Type> class template.

Definition at line 53 of file exceptions.hh.

◆ TYPEDEF_ERR_INFO

#define TYPEDEF_ERR_INFO (   EI_Type,
  Type 
)    typedef EI< struct EI_Type##_TAG, Type > EI_Type

Macro to simplify declaration of error_info types.

Is used to declare types of data that can be passed through exceptions from the throw point to the catch point, or possibly collect various data along stack rewinding when an exception is thrown.

Typical usage:

// declares type EI_ParticularNumber
TYPEDEF_ERR_INFO( EI_ParticularNumber, int);
// declares exception that use it
DECLARE_EXCEPTION(SomeException, << " Particular number: " << EI_ParticularNumber::val );
// ... some code ...
// here you pass particular number important for
// determination of cause of the exception
THROW( SomeException() << EI_ParticularNumber(10) );

Definition at line 194 of file exceptions.hh.

ExceptionBase
Base of exceptions used in Flow123d.
Definition: exceptions.hh:75
THROW
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
Definition: exceptions.hh:53
ExceptionBase::print_info
virtual void print_info(std::ostringstream &out) const =0
internal::ExcStream
Definition: exceptions.hh:324
TYPEDEF_ERR_INFO
#define TYPEDEF_ERR_INFO(EI_Type, Type)
Macro to simplify declaration of error_info types.
Definition: exceptions.hh:194
Input::Exception
Base of exceptions due to user input.
Definition: input_exception.hh:34
internal
Definition: field_values.cc:20
DECLARE_EXCEPTION
#define DECLARE_EXCEPTION(ExcName, Format)
Macro for simple definition of exceptions.
Definition: exceptions.hh:158