libexcept 1.1.19
Stack trace along C++ exceptions
Public Member Functions | Private Attributes | List of all members
libexcept::out_of_range_t Class Reference

#include <exception.h>

Inheritance diagram for libexcept::out_of_range_t:
Inheritance graph
[legend]
Collaboration diagram for libexcept::out_of_range_t:
Collaboration graph
[legend]

Public Member Functions

 out_of_range_t (char const *what, int const stack_trace_depth=STACK_TRACE_DEPTH)
 Initialize an exception from a C string.
 
 out_of_range_t (std::string const &what, int const stack_trace_depth=STACK_TRACE_DEPTH)
 Initialize an exception from a C++ string.
 
virtual ~out_of_range_t () override
 Destructor of the out_of_range exception class.
 
std::string get_parameter (std::string const &name) const
 Retrieve one of the exception parameters.
 
parameter_t const & get_parameters () const
 Retrieve the set of exception parameters.
 
stack_trace_t const & get_stack_trace () const
 Retrieve the stack trace.
 
exception_base_tset_parameter (std::string const &name, std::string const &value)
 Set a parameter in this exception.
 
virtual char const * what () const override throw ()
 Retrieve the what parameter as passed to the constructor.
 

Private Attributes

parameter_t f_parameters = parameter_t()
 
stack_trace_t f_stack_trace = stack_trace_t()
 The variable where the exception stack trace gets saved.
 

Detailed Description

Definition at line 97 of file exception.h.

Constructor & Destructor Documentation

◆ out_of_range_t() [1/2]

libexcept::out_of_range_t::out_of_range_t ( std::string const &  what,
int const  stack_trace_depth = STACK_TRACE_DEPTH 
)
explicit

This function initializes an exception settings its 'what' string to the specified what parameter.

Note
Out of Range exceptions are an extension of the Logic Exception used whenever a container is being accessed with an index which is too large. It may also be used whenever a number doesn't fit its destination variable (i.e. trying to return 300 in an int8_t).
Parameters
[in]whatThe string used to initialize the exception what parameter.
[in]stack_trace_depthThe number of lines to grab in our stack trace.

Definition at line 494 of file exception.cpp.

◆ out_of_range_t() [2/2]

libexcept::out_of_range_t::out_of_range_t ( char const *  what,
int const  stack_trace_depth = STACK_TRACE_DEPTH 
)
explicit

This function initializes an exception settings its 'what' string to the specified what parameter.

Note
Logic exceptions are used for things that just should not ever happen. More or less, a verification of your class contract that fails.
Parameters
[in]whatThe string used to initialize the exception what parameter.
[in]stack_trace_depthThe number of lines to grab in our stack trace.

Definition at line 524 of file exception.cpp.

◆ ~out_of_range_t()

libexcept::out_of_range_t::~out_of_range_t ( )
inlineoverridevirtual

This destructor is defined to ease derivation when some of the classes have virtual functions.

Definition at line 105 of file exception.h.

Member Function Documentation

◆ get_parameter()

std::string libexcept::exception_base_t::get_parameter ( std::string const &  name) const
inherited

Exceptions can be assigned parameters with the set_parameter() function. For example, you could include a filename as a parameter. This is useful when sending logs to a database. It can simplify your searches to know exact parameters instead of trying to parse strings.

Parameters
[in]nameThe name of the parameter to search for.
Returns
The value of the named parameter.

Definition at line 346 of file exception.cpp.

References libexcept::exception_base_t::f_parameters.

◆ get_parameters()

parameter_t const & libexcept::exception_base_t::get_parameters ( ) const
inherited

This function returns a reference to all the parameters found in this exception. In most cases, exceptions do not have parameters, however, we intend to change that as we continue work on our libraries.

Returns
The reference to this exception parameters.

Definition at line 329 of file exception.cpp.

References libexcept::exception_base_t::f_parameters.

◆ get_stack_trace()

libexcept::exception_base_t::get_stack_trace ( ) const
inlineinherited

This function retreives a reference to the vector of strings representing the stack trace at the time the exception was raised.

Definition at line 75 of file exception.h.

References libexcept::exception_base_t::f_stack_trace.

◆ set_parameter()

exception_base_t & libexcept::exception_base_t::set_parameter ( std::string const &  name,
std::string const &  value 
)
inherited

You may add parameters to your exceptions simply by calling this function.

Parameters are given a name. At the moment the name is not restricted, however, if you want to make sure that it works in most places (i.e. in the snaplogger), then you probably want to limit the name to this regex:

[A-Za-z_][A-Za-z_0-9]*

Parameter values are strings.

This is an exception, so we do not raise an exception if the name of a parameter is considered invalid. At the moment, an empty string is considered invalid.

Parameters
[in]nameThe name of the parameter. It cannot be empty.
[in]valueThe value of this parameter.
Returns
A reference to this exception.

Definition at line 381 of file exception.cpp.

References libexcept::exception_base_t::f_parameters.

◆ what()

char const * libexcept::out_of_range_t::what ( ) const
throw (
)
overridevirtual

This function returns the what description of the exception when the exception was initialized.

Note
We have an overload because of the dual derivation.
Returns
A pointer to the what string. Must be used before the exception gets destructed.

Definition at line 544 of file exception.cpp.

Member Data Documentation

◆ f_parameters

parameter_t libexcept::exception_base_t::f_parameters = parameter_t()
privateinherited

◆ f_stack_trace

stack_trace_t libexcept::exception_base_t::f_stack_trace = stack_trace_t()
privateinherited

This parameter holds the vector of strings representing the stack trace at the time an exception was raised and an instance of the exception_base_t class was created.

Definition at line 79 of file exception.h.

Referenced by libexcept::exception_base_t::exception_base_t(), and libexcept::exception_base_t::get_stack_trace().


The documentation for this class was generated from the following files:

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.