libpnicore
Data Structures | Macros | Functions
Exception classes

Data Structures

class  pni::core::exception_record
 exception record More...
 
class  pni::core::exception
 Exceptions base class. More...
 
class  pni::core::memory_allocation_error
 memory allocation error More...
 
class  pni::core::memory_not_allocated_error
 memory not allocated error More...
 
class  pni::core::shape_mismatch_error
 Shape mismatch error. More...
 
class  pni::core::size_mismatch_error
 Size mismatch error. More...
 
class  pni::core::index_error
 index error More...
 
class  pni::core::key_error
 key error More...
 
class  pni::core::file_error
 file IO fails More...
 
class  pni::core::type_error
 data type error More...
 
class  pni::core::value_error
 data value error More...
 
class  pni::core::range_error
 data range error More...
 
class  pni::core::not_implemented_error
 not implemented exception More...
 
class  pni::core::iterator_error
 iterator error More...
 
class  pni::core::cli_argument_error
 command line argument error More...
 
class  pni::core::cli_option_error
 command line option error More...
 
class  pni::core::cli_error
 general CLI error More...
 

Macros

#define EXCEPTION_RECORD   exception_record(__FILE__,__LINE__,BOOST_CURRENT_FUNCTION)
 macro creating an instance of ExceptionRecord
 
#define EXCEPTION_FORWARD(ETYPE)
 forward an exception More...
 

Functions

template<typename VTYPE >
void pni::core::print_vector (std::ostream &o, const VTYPE &v)
 print vector content More...
 
template<typename A , typename B >
bool pni::core::check_equal_size (const A &a, const B &b)
 check if two container have equal size More...
 
template<typename A , typename B >
void pni::core::check_equal_size (const A &a, const B &b, const exception_record &i)
 check if two objects have different size More...
 
bool pni::core::check_index_in_dim (size_t index, size_t dimsize)
 check index in dim More...
 
void pni::core::check_index_in_dim (size_t index, size_t dimsize, const exception_record &i)
 check index in dim More...
 
template<typename ITYPE , typename STYPE >
bool pni::core::check_indexes (const ITYPE &index, const STYPE &shape)
 check indexes More...
 
template<typename ITYPE , typename STYPE >
void pni::core::check_indexes (const ITYPE &index, const STYPE &shape, const exception_record &record)
 check indexes More...
 
template<typename A , typename B >
bool pni::core::check_equal_rank (const A &a, const B &b)
 check equal rank More...
 
template<typename A , typename B >
void pni::core::check_equal_rank (const A &a, const B &b, const exception_record &i)
 check equal rank More...
 
template<typename A , typename B >
bool pni::core::check_equal_shape (const A &a, const B &b)
 check for shape equality
 
template<typename A , typename B >
void pni::core::check_equal_shape (const A &a, const B &b, const exception_record &i)
 check shape equality More...
 
template<typename OTYPE >
void pni::core::check_allocation_state (const OTYPE &o, const exception_record &i)
 check allocation state More...
 
template<typename T >
void pni::core::check_ptr_state (const T *ptr, const exception_record &i)
 check pointer state More...
 
std::ostream & pni::core::operator<< (std::ostream &o, const exception_record &rec)
 error record output operator
 

Detailed Description

In version 0.2.5 the exception backend has undergone a major rewrite. The old macros are no longer available. Exceptions provide much more detailed information about where they are thrown and can be stacked to provide a kind of stack trace where an exception has occurred and how it was propagated through the code. All information where an exception occurred is stored in an instance of ExceptionRecord. An instance of this class can easily created using the EXCEPTION_RECORD macro (as in most cases the construction of an ExceptionRecord will look equal). An exception record includes the exact signature of the method or function, the line in the file, and the source file name where the exception was thrown. This should make it easier to identify the location where an exception occurred.

Macro Definition Documentation

#define EXCEPTION_FORWARD (   ETYPE)
Value:
catch(ETYPE &error)\
{\
error.append(EXCEPTION_RECORD);\
throw error;\
}
#define EXCEPTION_RECORD
macro creating an instance of ExceptionRecord
Definition: exceptions.hpp:48

This macro can be used to forward an exception caught from another function. It appends the exception_record of the current function to the existing exception and throws the exception again. Consider the following examples

1 try { value = buffer.at(index); }
2 EXCEPTION_FORWARD(IndexError)
3 EXCEPTION_FORWARD(MemoryNotAllocatedError)

Please note that the MUST NOT BE a semicolon at the end of this macro.

Function Documentation

template<typename OTYPE >
void pni::core::check_allocation_state ( const OTYPE &  o,
const exception_record &  i 
)

Checks the allocation state of an allocateable object. If the object is not allocated an exception will be thrown.

Exceptions
memory_not_allocated_errorif object not allocated
Parameters
oobject to check
iexception_record for the location where to perform the check
template<typename A , typename B >
bool pni::core::check_equal_rank ( const A &  a,
const B &  b 
)

Return true of the two array like objects have an equal number of dimensions. In any other case return false.

Template Parameters
Afirst array type
Bsecond array type
Parameters
areference to an instance of A
breference to an instance of B
Returns
true if a and b have equal rank, false otherwise
template<typename A , typename B >
void pni::core::check_equal_rank ( const A &  a,
const B &  b,
const exception_record &  i 
)

Throwing version of check_equal_rank.

Exceptions
shape_mismatch_errorif a and b have different rank
Template Parameters
Afirst array type
Bsecond array type
Parameters
areference to an instance of A
breference to an instance of B
iexception record of the calling function
template<typename A , typename B >
void pni::core::check_equal_shape ( const A &  a,
const B &  b,
const exception_record &  i 
)

Checks if two Shape objects are equal and throws an exception if they are not.

Template Parameters
Acontainer type for the first shape
Bcontainer type for the second shape
Exceptions
size_mismatch_errorif array sizes do not match
shape_mismatch_errorif shapes do not match
Parameters
afirst shape
bsecond shape
iexception_record for the location where to perform the check
template<typename A , typename B >
bool pni::core::check_equal_size ( const A &  a,
const B &  b 
)

This helper function checks if two container instances have equal size and returns true if this is the case. Otherwise false will be returned. Both container types have to provide a size() method returning the number of elements the container can hold.

Template Parameters
Afirst container type
Bsecond container type
Parameters
areference to an instance of A
breference to an instance of B
Returns
true if a and b have same size, false otherwise
template<typename A , typename B >
void pni::core::check_equal_size ( const A &  a,
const B &  b,
const exception_record &  i 
)

This utilty function can be used to check for the equality of the size of two objects. It is typically used to compare the size of a shape and a buffer or any other container object. If the sizes do not match an exception is thrown.

Exceptions
size_mismatch_errorif sizes do not match
Template Parameters
Afirst container type
Bsecond container type
Parameters
ainstance of container type A
binstance of container type B
iexception_record for the location where to perform the check performed
bool pni::core::check_index_in_dim ( size_t  index,
size_t  dimsize 
)

Check if an index resides within a dimension range. The index must be than the size of the dimension. If the index is within the dimension size true is returned. false otherwise.

Parameters
indexthe index to check
dimsizesize of the dimension
Returns
true if index<dimsize, flase otherwise
void pni::core::check_index_in_dim ( size_t  index,
size_t  dimsize,
const exception_record &  i 
)

Throwing version of check_index_in_dim. Throws an index_error exception if the index is not within the dimension range.

Exceptions
index_errorif i exceeds dimsize
Parameters
indexactual index
dimsizedimension size
iexception_record for the location where to perform the check performed
template<typename ITYPE , typename STYPE >
bool pni::core::check_indexes ( const ITYPE &  index,
const STYPE &  shape 
)

Check if all index values stored in a container do not exceed their dimensions limits.

Template Parameters
ITYPEindex container type
STYPEshape container type
Parameters
indexreference to an index container
shapereference to a shape container
Returns
true if all indexes are in their bounds
template<typename ITYPE , typename STYPE >
void pni::core::check_indexes ( const ITYPE &  index,
const STYPE &  shape,
const exception_record &  record 
)

Checks if all indexes stored in a container lie within a given range determined by the shape. In addition the function checks if the number of indexes matches the number of elements in the shape.

Exceptions
index_errorif one of the indexes exceeds the number of elements in its dimension
shape_mismatch_errorif the number of indexes does not match the number of dimensions (elements in the shape)
Template Parameters
ITYPEindex container type
STYPEshape container type
Parameters
indexcontainer with index data
shapecontainer with shape data
recordthe exception record of the calling function
template<typename T >
void pni::core::check_ptr_state ( const T *  ptr,
const exception_record &  i 
)

Checks if a pointer is nullptr or not and throws an exception if it is.

Exceptions
memory_not_allocated_errorif pointer is a nullptr
Parameters
ptrpointer to check
iexception_record for the location where to perform the check
template<typename VTYPE >
void pni::core::print_vector ( std::ostream &  o,
const VTYPE &  v 
)

Print the content of an interable as a vector. The output is embraced by () and each element is separated by a comma.

Template Parameters
VTYPEcontainer type
Parameters
ooutput stream
viterable instance