[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
12.1 Error handling | ||
12.2 Floating-point underflow | ||
12.3 Customizing I/O | ||
12.4 Customizing the memory allocator |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
CLN signals abnormal situations by throwning exceptions. All exceptions
thrown by the library are of type runtime_exception
or of a
derived type. Class cln::runtime_exception
in turn is derived
from the C++ standard library class std::runtime_error
and
inherits the .what()
member function that can be used to query
details about the cause of error.
The most important classes thrown by the library are
Exception base class runtime_exception <cln/exception.h> | +----------------+----------------+ | | Malformed number input Floating-point error read_number_exception floating_poing_exception <cln/number_io.h> <cln/float.h> |
CLN has many more exception classes that allow for more fine-grained control but I refrain from documenting them all here. They are all declared in the public header files and they are all subclasses of the above exceptions, so catching those you are always on the safe side.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Floating point underflow denotes the situation when a floating-point
number is to be created which is so close to 0
that its exponent
is too low to be represented internally. By default, this causes the
exception floating_point_underflow_exception
(subclass of
floating_point_exception
) to be thrown. If you set the global
variable
bool cl_inhibit_floating_point_underflow |
to true
, the exception will be inhibited, and a floating-point
zero will be generated instead. The default value of
cl_inhibit_floating_point_underflow
is false
.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The output of the function fprint
may be customized by changing the
value of the global variable default_print_flags
.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Every memory allocation of CLN is done through the function pointer
malloc_hook
. Freeing of this memory is done through the function
pointer free_hook
. The default versions of these functions,
provided in the library, call malloc
and free
and check
the malloc
result against NULL
.
If you want to provide another memory allocator, you need to define
the variables malloc_hook
and free_hook
yourself,
like this:
#include <cln/malloc.h> namespace cln { void* (*malloc_hook) (size_t size) = …; void (*free_hook) (void* ptr) = …; } |
The cl_malloc_hook
function must not return a NULL
pointer.
It is not possible to change the memory allocator at runtime, because it is already called at program startup by the constructors of some global variables.
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated by Richard B. Kreckel on January, 19 2008 using texi2html 1.76.