OpenVPN 3 Core Library
Loading...
Searching...
No Matches
openvpn::BufferException Class Reference

report various types of exceptions or errors that may occur when working with buffers More...

#include <buffer.hpp>

Inheritance diagram for openvpn::BufferException:
[legend]
Collaboration diagram for openvpn::BufferException:
[legend]

Public Types

enum  Status {
  buffer_full , buffer_headroom , buffer_underflow , buffer_overflow ,
  buffer_offset , buffer_index , buffer_const_index , buffer_push_front_headroom ,
  buffer_no_reset_impl , buffer_pop_back , buffer_set_size , buffer_range
}
 

Public Member Functions

 BufferException (Status status)
 
 BufferException (Status status, const std::string &msg)
 
const char * what () const noexcept override
 
Status status () const
 
virtual ~BufferException () noexcept=default
 

Static Private Member Functions

static const char * status_string (const Status status)
 

Private Attributes

Status status_
 
std::string msg_
 

Detailed Description

report various types of exceptions or errors that may occur when working with buffers

defines a C++ class called BufferException which is derived from the standard std::exception class. The purpose of this class is to provide a way to handle and report various types of exceptions or errors that may occur when working with buffers (data containers) in the OpenVPN application.

The BufferException class does not take any direct input. Instead, it is designed to be instantiated and thrown (raised) when certain exceptional conditions arise during buffer operations. The class defines an enumeration Status that lists various types of buffer-related exceptions, such as buffer_full, buffer_underflow, buffer_overflow, buffer_offset, and others.

When a BufferException is thrown, it can be caught and handled by the calling code. The output produced by this class is an error message that describes the specific type of exception that occurred. This error message can be obtained by calling the what() member function, which returns a C-style string (const char*) containing the error description.

The class achieves its purpose through the following logic and algorithm:

The BufferException class has two constructors: one that takes only a Status value, and another that takes both a Status value and an additional error message string. The what() member function is overridden from the base std::exception class. It returns the error message associated with the exception. If an additional error message string was provided during construction, the what() function returns a combination of the status string (e.g., "buffer_full") and the additional message. If no additional message was provided, the what() function returns only the status string. The status_string() private static member function is used to convert the Status enumeration value to a corresponding string representation (e.g., "buffer_full" for buffer_full).

The important logic flow in this code is the conversion of the Status enumeration value to a human-readable string representation, which is then used to construct the error message returned by the what() function. This error message can be used by the calling code to understand the nature of the exception and take appropriate action.

It's important to note that this code does not handle any data transformations or perform any complex algorithms. Its sole purpose is to provide a mechanism for reporting and handling buffer-related exceptions in a consistent and descriptive manner.

Definition at line 113 of file buffer.hpp.

Member Enumeration Documentation

◆ Status

Enumerator
buffer_full 
buffer_headroom 
buffer_underflow 
buffer_overflow 
buffer_offset 
buffer_index 
buffer_const_index 
buffer_push_front_headroom 
buffer_no_reset_impl 
buffer_pop_back 
buffer_set_size 
buffer_range 

Definition at line 116 of file buffer.hpp.

Constructor & Destructor Documentation

◆ BufferException() [1/2]

openvpn::BufferException::BufferException ( Status  status)
inlineexplicit

Definition at line 132 of file buffer.hpp.

◆ BufferException() [2/2]

openvpn::BufferException::BufferException ( Status  status,
const std::string &  msg 
)
inline

Definition at line 137 of file buffer.hpp.

◆ ~BufferException()

virtual openvpn::BufferException::~BufferException ( )
virtualdefaultnoexcept

Member Function Documentation

◆ status()

Status openvpn::BufferException::status ( ) const
inline

Definition at line 151 of file buffer.hpp.

Here is the caller graph for this function:

◆ status_string()

static const char * openvpn::BufferException::status_string ( const Status  status)
inlinestaticprivate

Definition at line 158 of file buffer.hpp.

Here is the caller graph for this function:

◆ what()

const char * openvpn::BufferException::what ( ) const
inlineoverridenoexcept

Definition at line 143 of file buffer.hpp.

Here is the caller graph for this function:

Member Data Documentation

◆ msg_

std::string openvpn::BufferException::msg_
private

Definition at line 192 of file buffer.hpp.

◆ status_

Status openvpn::BufferException::status_
private

Definition at line 191 of file buffer.hpp.


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