Flow123d  release_2.2.0-914-gf1a3a4f
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

#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 () {} \
}
Base of exceptions used in Flow123d.
Definition: exceptions.hh:75
virtual void print_info(std::ostringstream &out) const =0

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:

1 TYPEDEF_ERR_INFO( EI_Dim1Mismatch, int);
2 TYPEDEF_ERR_INFO( EI_Dim2Mismatch, int);
3 DECLARE_EXCEPTION( ExcDimensionMismatch,
4  << "Dimensions dim1=" << EI_Dim1Missmatch::val
5  << " 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:

1 class Matrix;
2 TYPEDEF_ERR_INFO( EI_Matrix, Matrix);
3 DECLARE_EXCEPTION( ExcWrongMatrixState,
4  << "Matrix state: " << EI_Matrix::ptr(*this)->state() << "\n"
5  << "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.

#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 () {} \
}
Base of exceptions due to user input.
virtual void print_info(std::ostringstream &out) const =0

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.

#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:

1 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.

#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:

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

Definition at line 194 of file exceptions.hh.