UtilsLite
Utilities for C++ programming
Loading...
Searching...
No Matches
Utils::Runtime_Error Class Reference

Custom runtime error class for handling runtime exceptions. More...

#include <Utils_fmt.hh>

Inheritance diagram for Utils::Runtime_Error:

Public Member Functions

 Runtime_Error (string_view reason, string_view file, int line)
 Constructs a Runtime_Error instance with a given reason.
 
char const * what () const noexcept override
 Returns a C-style string describing the error.
 

Detailed Description

Custom runtime error class for handling runtime exceptions.

This class extends the standard std::runtime_error to include additional context information, specifically the file name and line number where the error occurred. It provides constructors that accept a reason for the error and formats the error message accordingly.

Usage

try {
throw Runtime_Error("An error occurred", __FILE__, __LINE__);
} catch (const Runtime_Error& e) {
std::cerr << e.what();
}
Custom runtime error class for handling runtime exceptions.
Definition Utils_fmt.hh:119
Runtime_Error(string_view reason, string_view file, int line)
Constructs a Runtime_Error instance with a given reason.
Definition Utils_fmt.hh:133
char const * what() const noexcept override
Returns a C-style string describing the error.

Constructor & Destructor Documentation

◆ Runtime_Error()

Utils::Runtime_Error::Runtime_Error ( string_view reason,
string_view file,
int line )
inlineexplicit

Constructs a Runtime_Error instance with a given reason.

This constructor initializes the error with a specified reason, the file where the error occurred, and the line number. It formats the error message accordingly.

Parameters
reasonA string that describes the reason for the error.
fileThe name of the file where the error occurred.
lineThe line number in the file where the error occurred.

Member Function Documentation

◆ what()

char const * Utils::Runtime_Error::what ( ) const
overridenoexcept

Returns a C-style string describing the error.

This method overrides the what() method from std::runtime_error to provide a more detailed error message, including the reason for the error, the file name, and the line number.

Returns
A C-style string representing the error message.

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