Exceptions¶
pni::core::exception_record¶
-
class
exception_record¶ exception record
Contains the basic information where an exception has been thrown. This information consists of the source file, the line in the file, and the signature of the function where the error occurred. Using the BOOST_CURRENT_FUNCTION macro defined in boost/current_function.hpp such a record can easily be constructed with
exception_record r(__FILE__,__LINE__,BOOST_CURRENT_FUNCTION);
Warning
doxygenfunction: Unable to resolve multiple matches for function “operator<<” with arguments (std::ostream &, const exception_record &) in doxygen xml output for project “pnicore” from directory: /home/jkotan/sources/libpnicore-build/doc/api_doc/xml. Potential matches:
- PNICORE_EXPORT std::ostream &pni::core::operator<<(std::ostream&, const bool_t&)
- PNICORE_EXPORT std::ostream &pni::core::operator<<(std::ostream&, const exception_record&)
- PNICORE_EXPORT std::ostream &pni::core::operator<<(std::ostream&, const none&)
- PNICORE_EXPORT std::ostream &pni::core::operator<<(std::ostream&, const slice&)
- PNICORE_EXPORT std::ostream &pni::core::operator<<(std::ostream&, const type_id_t&)
- std::ostream &pni::core::operator<<(std::ostream&, const array_selection&)
- std::ostream &pni::core::operator<<(std::ostream&, const benchmark_result&)
- std::ostream &pni::core::operator<<(std::ostream&, const cli_args&)
- std::ostream &pni::core::operator<<(std::ostream&, const cli_argument_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const cli_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const cli_help_request&)
- std::ostream &pni::core::operator<<(std::ostream&, const cli_option_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const configuration&)
- std::ostream &pni::core::operator<<(std::ostream&, const exception&)
- std::ostream &pni::core::operator<<(std::ostream&, const file_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const index_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const iterator_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const key_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const memory_allocation_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const memory_not_allocated_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const not_implemented_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const range_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const shape_mismatch_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const size_mismatch_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const type_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const value_error&)
- template <typename ATYPE>
std::ostream &pni::core::operator<<(std::ostream&, const array_view<ATYPE>&)
- template <typename NTYPE>
std::ostream &pni::core::operator<<(std::ostream&, const binary_t<NTYPE>&)
- template <typename STORAGE, typename IMAP, typename IPA>
std::ostream &pni::core::operator<<(std::ostream&, const mdarray<STORAGE, IMAP, IPA>&)
- template <typename T>
std::ostream &pni::core::operator<<(std::ostream&, const scalar<T>&)
pni::core::exception¶
-
class
exception: public std::exception¶ Exceptions base class.
This is the base class for all exceptions used in this library.
Subclassed by pni::core::cli_argument_error, pni::core::cli_error, pni::core::cli_help_request, pni::core::cli_option_error, pni::core::file_error, pni::core::index_error, pni::core::iterator_error, pni::core::key_error, pni::core::memory_allocation_error, pni::core::memory_not_allocated_error, pni::core::not_implemented_error, pni::core::range_error, pni::core::shape_mismatch_error, pni::core::size_mismatch_error, pni::core::type_error, pni::core::value_error
Public Types
-
typedef std::list<exception_record>::const_iterator
const_iterator¶ const iterator over the error record
Public Functions
-
exception()¶ default constructor
-
exception(const string &n)¶ constructor
- Parameters
n: name of the exception
-
exception(const string &n, const exception_record &rec)¶ constructor
- Parameters
n: name of the exceptionrec: Exception record of the initial location where the error occured
-
exception(const string &n, const exception_record &rec, const string &d)¶ constructor
- Parameters
n: name of the exceptionrec: exception record describing the location of the first occurrence of the errord: description of the exception
-
virtual
~exception()¶ virtual destructor
-
void
name(const std::string &name)¶ set the exception name
- Parameters
name: exception name
-
const string &
name() const¶ get the exceptions name
- Return
- reference to the string object holding the name
-
void
append(const exception_record &n)¶ add a new issuer
Use this method to add a new issuer in the case that the exception is re-thrown by an other function or class method.
With this a particular exception can be traced througout the entire code.... catch(exception &error) { error.append(EXCEPTION_RECORD); throw error; }
- Parameters
n: exception_record to append
-
void
description(const std::string &desc)¶ set exception desccription
- Parameters
desc: description of the exception
-
const string &
description() const¶ get the exceptions description
- Return
- reference to the string object with the exceptions description
-
size_t
size() const¶ get number of record
Returns the number of records associated with this exception.
- Return
- number of records
-
const_iterator
begin() const¶ get iterator to first error record
Return get a const iterator to the first error record in the class.
- Return
- iterator to first exception record
-
const_iterator
end() const¶ get iterator to the last error record
Return a const iterator pointing to the last+1 element in the exception record list.
- Return
- iterator to last+1 exception record
Friends
-
PNICORE_EXPORT std::ostream &
operator<<(std::ostream &ostr, const exception &ex)¶ output operator for exceptions
-
typedef std::list<exception_record>::const_iterator
Exception classes¶
These classes have the same interface as pni::core::exception but
denote different failure situations.
-
class
memory_allocation_error: public pni::core::exception¶ memory allocation error
This exception is typically raised when allocation of memory on the heap fails. In other words when a call to new leads to a nullptr.
-
class
memory_not_allocated_error: public pni::core::exception¶ memory not allocated error
This exception is usually thrown if one tries to access not allocated memory.
-
class
shape_mismatch_error: public pni::core::exception¶ Shape mismatch error.
Raised in cases where the Shape objects of two objects are not equal.
-
class
size_mismatch_error: public pni::core::exception¶ Size mismatch error.
This exception will be raised in cases where buffer sizes do not meet the requirements.
-
class
index_error: public pni::core::exception¶ index error
Raised if the index passed to a [] operator exceeds the size of the container it belongs to.
-
class
key_error: public pni::core::exception¶ key error
Raised in cases where a problem with the key of a hash map occurs.
-
class
file_error: public pni::core::exception¶ file IO fails
Raised typically in cases of problems with files.
-
class
type_error: public pni::core::exception¶ data type error
This exception is raised in cases of errors concerning data types.
-
class
value_error: public pni::core::exception¶ data value error
This exception is raised in cases where a particular variable takes an inappropriate value.
-
class
range_error: public pni::core::exception¶ data range error
This exception is raised in cases where data values exceed the range spanned by their data type.
-
class
not_implemented_error: public pni::core::exception¶ not implemented exception
This exception can be used to mark methods of abstract or base classes as not implemented. Such an approach can be quite useful for debugging and development.
-
class
iterator_error: public pni::core::exception¶ iterator error
Exception thrown in case of iterator errors.
-
class
cli_argument_error: public pni::core::exception¶ command line argument error
Thrown in cases where a command line argument (do not confuse this with an option has an inapropriate value or is missing).
Macros¶
-
EXCEPTION_RECORD¶ macro creating an instance of ExceptionRecord
-
EXCEPTION_FORWARD(ETYPE)¶ forward an exception
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
Please note that the MUST NOT BE a semicolon at the end of this macro.try { value = buffer.at(index); } EXCEPTION_FORWARD(IndexError) EXCEPTION_FORWARD(MemoryNotAllocatedError)
Utility functions¶
Warning
doxygenfunction: Unable to resolve multiple matches for function “check_equal_size” with arguments (const A &, const B &) in doxygen xml output for project “pnicore” from directory: /home/jkotan/sources/libpnicore-build/doc/api_doc/xml. Potential matches:
- template <typename A, typename B>
bool pni::core::check_equal_size(const A&, const B&)
- template <typename A, typename B>
void pni::core::check_equal_size(const A&, const B&, const exception_record&)
- template <typename CTYPE, typename ... *CTYPES*>
bool pni::core::check_equal_size(const CTYPE&, const CTYPES&...)
Warning
doxygenfunction: Unable to resolve multiple matches for function “check_equal_size” with arguments (const A &, const B &, const exception_record &) in doxygen xml output for project “pnicore” from directory: /home/jkotan/sources/libpnicore-build/doc/api_doc/xml. Potential matches:
- template <typename A, typename B>
bool pni::core::check_equal_size(const A&, const B&)
- template <typename A, typename B>
void pni::core::check_equal_size(const A&, const B&, const exception_record&)
- template <typename CTYPE, typename ... *CTYPES*>
bool pni::core::check_equal_size(const CTYPE&, const CTYPES&...)