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

#include <exception.h>

Inheritance diagram for libexcept::exception_base_t:
Inheritance graph
[legend]

Public Member Functions

 exception_base_t (int const stack_trace_depth=STACK_TRACE_DEPTH)
 Initialize this Snap! exception.
 
virtual ~exception_base_t ()
 Destructor of the exception base 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.
 

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 64 of file exception.h.

Constructor & Destructor Documentation

◆ exception_base_t()

libexcept::exception_base_t::exception_base_t ( int const  stack_trace_depth = STACK_TRACE_DEPTH)
explicit

Initialize the base exception class by generating the output of a stack trace to a list of strings.

Warning
At this time every single exception derived from exception_t generates a stack trace. Note that in most cases, our philosophy is to generate exceptions only in very exceptional cases and not on every single error so the event should be rare in a normal run of our daemons.
Parameters
[in]stack_trace_depthThe number of lines to grab in our stack trace.
See also
collect_stack_trace()

Definition at line 294 of file exception.cpp.

References libexcept::COLLECT_STACK_COMPLETE, libexcept::COLLECT_STACK_NO, libexcept::collect_stack_trace(), libexcept::collect_stack_trace_with_line_numbers(), libexcept::COLLECT_STACK_YES, f_stack_trace, and libexcept::get_collect_stack().

◆ ~exception_base_t()

libexcept::exception_base_t::~exception_base_t ( )
inlinevirtual

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

Definition at line 69 of file exception.h.

Member Function Documentation

◆ get_parameter()

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

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

◆ get_parameters()

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

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

◆ get_stack_trace()

libexcept::exception_base_t::get_stack_trace ( ) const
inline

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

◆ set_parameter()

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

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

Member Data Documentation

◆ f_parameters

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

Definition at line 78 of file exception.h.

Referenced by get_parameter(), get_parameters(), and set_parameter().

◆ f_stack_trace

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

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 exception_base_t(), and 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.