Scarab  v3.9.4
Project 8 C++ Utility Library
Public Member Functions | Protected Attributes | List of all members
typed_exception< x_derived > Class Template Reference

Base class for exceptions with streaming operators and filename/line number location. More...

#include <base_exception.hh>

Inheritance diagram for typed_exception< x_derived >:
Inheritance graph

Public Member Functions

 typed_exception () noexcept
 
 typed_exception (const std::string &a_filename, int a_line) noexcept
 
 typed_exception (const typed_exception< x_derived > &a_orig) noexcept
 
virtual ~typed_exception () noexcept
 
typed_exception< x_derived > & operator= (const typed_exception< x_derived > &a_orig)
 
template<class x_streamable >
x_derived & operator<< (x_streamable a_fragment)
 
x_derived & operator<< (const std::string &a_fragment)
 
x_derived & operator<< (const char *a_fragment)
 
x_derived & operator() (const std::string &a_filename, int a_line)
 
virtual const char * what () const noexcept
 
virtual const char * where () const noexcept
 
const std::string & filename () const
 
int line () const
 
- Public Member Functions inherited from base_exception
 base_exception () noexcept=default
 
virtual ~base_exception () noexcept=default
 

Protected Attributes

std::string f_what
 
std::string f_where
 
std::string f_filename
 
int f_line
 

Detailed Description

template<typename x_derived>
class scarab::typed_exception< x_derived >

Base class for exceptions with streaming operators and filename/line number location.

Author
N.S. Oblath

This class provides streaming operators for building up the what() message. It's meant to be the base class for any exceptions wanting to use that feature.

The where() message can be filled with the filename and line number using a constructor or operator().

This class uses the Curiously Recurring Template Pattern (CRTP) to get the derived class type to appear in the base class. In particular, we need to return x_derived& from the various operator<<() so that those functions can be used in a throw statement and the user can still catch the derived type.

Definition at line 55 of file base_exception.hh.

Constructor & Destructor Documentation

◆ typed_exception() [1/3]

typed_exception ( )
noexcept

Definition at line 87 of file base_exception.hh.

◆ typed_exception() [2/3]

typed_exception ( const std::string &  a_filename,
int  a_line 
)
noexcept

Definition at line 96 of file base_exception.hh.

◆ typed_exception() [3/3]

typed_exception ( const typed_exception< x_derived > &  a_orig)
noexcept

Definition at line 114 of file base_exception.hh.

◆ ~typed_exception()

~typed_exception ( )
virtualnoexcept

Definition at line 132 of file base_exception.hh.

Member Function Documentation

◆ filename()

const std::string & filename ( ) const

Definition at line 195 of file base_exception.hh.

◆ line()

int line ( ) const

Definition at line 201 of file base_exception.hh.

◆ operator()()

x_derived & operator() ( const std::string &  a_filename,
int  a_line 
)

Definition at line 187 of file base_exception.hh.

◆ operator<<() [1/3]

x_derived & operator<< ( x_streamable  a_fragment)

Definition at line 164 of file base_exception.hh.

◆ operator<<() [2/3]

x_derived & operator<< ( const std::string &  a_fragment)

Definition at line 173 of file base_exception.hh.

◆ operator<<() [3/3]

x_derived & operator<< ( const char *  a_fragment)

Definition at line 180 of file base_exception.hh.

◆ operator=()

typed_exception< x_derived > & operator= ( const typed_exception< x_derived > &  a_orig)

Definition at line 136 of file base_exception.hh.

◆ what()

const char * what ( ) const
virtualnoexcept

Definition at line 143 of file base_exception.hh.

◆ where()

const char * where ( ) const
virtualnoexcept

Implements base_exception.

Definition at line 149 of file base_exception.hh.

Member Data Documentation

◆ f_filename

std::string f_filename
protected

Definition at line 82 of file base_exception.hh.

◆ f_line

int f_line
protected

Definition at line 83 of file base_exception.hh.

◆ f_what

std::string f_what
mutableprotected

Definition at line 79 of file base_exception.hh.

◆ f_where

std::string f_where
mutableprotected

Definition at line 80 of file base_exception.hh.


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