Common System 0.2.0
Common interfaces and patterns for system integration
Loading...
Searching...
No Matches
kcenon::common::common_error_category Class Reference

Error category for common/shared error codes. More...

#include <error_category.h>

Inheritance diagram for kcenon::common::common_error_category:
Inheritance graph
Collaboration diagram for kcenon::common::common_error_category:
Collaboration graph

Public Types

enum  codes : int {
  success = 0 , unknown_error = -1 , invalid_argument = -2 , not_found = -3 ,
  permission_denied = -4 , timeout = -5 , cancelled = -6 , not_initialized = -7 ,
  already_exists = -8 , out_of_memory = -9 , io_error = -10 , operation_not_supported = -11 ,
  internal_error = -99
}
 Common error codes. More...
 

Public Member Functions

std::string_view name () const noexcept override
 Returns the category name.
 
std::string message (int code) const override
 Returns a human-readable message for the error code.
 
- Public Member Functions inherited from kcenon::common::error_category
virtual ~error_category ()=default
 Virtual destructor for proper cleanup of derived classes.
 
virtual bool equivalent (int code, const error_category &other_category, int other_code) const noexcept
 Checks if an error code in this category is equivalent to another.
 
bool operator== (const error_category &other) const noexcept
 Equality comparison between categories.
 
bool operator!= (const error_category &other) const noexcept
 Inequality comparison between categories.
 
bool operator< (const error_category &other) const noexcept
 Less-than comparison for use in ordered containers.
 

Static Public Member Functions

static const common_error_categoryinstance () noexcept
 Returns the singleton instance of common_error_category.
 

Private Member Functions

 common_error_category ()=default
 

Additional Inherited Members

- Protected Member Functions inherited from kcenon::common::error_category
 error_category ()=default
 Protected default constructor.
 
 error_category (const error_category &)=delete
 
error_categoryoperator= (const error_category &)=delete
 
 error_category (error_category &&)=delete
 
error_categoryoperator= (error_category &&)=delete
 

Detailed Description

Error category for common/shared error codes.

This category contains error codes that are truly common across all systems:

  • Success/failure indicators
  • Generic errors (invalid_argument, not_found, etc.)
  • Resource errors (out_of_memory, timeout)

System-specific errors should NOT be added here. Instead, each system should define its own error category.

Definition at line 176 of file error_category.h.

Member Enumeration Documentation

◆ codes

Common error codes.

These are error codes that apply universally across all systems. System-specific error codes should be defined in their respective error categories.

Enumerator
success 
unknown_error 
invalid_argument 
not_found 
permission_denied 
timeout 
cancelled 
not_initialized 
already_exists 
out_of_memory 
io_error 
operation_not_supported 
internal_error 

Definition at line 185 of file error_category.h.

185 : int {
186 success = 0,
187 unknown_error = -1,
188 invalid_argument = -2,
189 not_found = -3,
191 timeout = -5,
192 cancelled = -6,
193 not_initialized = -7,
194 already_exists = -8,
195 out_of_memory = -9,
196 io_error = -10,
198 internal_error = -99
199 };

Constructor & Destructor Documentation

◆ common_error_category()

kcenon::common::common_error_category::common_error_category ( )
privatedefault

Member Function Documentation

◆ instance()

static const common_error_category & kcenon::common::common_error_category::instance ( )
inlinestaticnoexcept

Returns the singleton instance of common_error_category.

Thread-safe due to C++11 static local variable initialization.

Returns
Reference to the singleton instance

Definition at line 208 of file error_category.h.

208 {
209 static common_error_category inst;
210 return inst;
211 }

Referenced by kcenon::common::typed_error_code::clear(), and kcenon::common::make_typed_error_code().

Here is the caller graph for this function:

◆ message()

std::string kcenon::common::common_error_category::message ( int code) const
inlineoverridevirtual

Returns a human-readable message for the error code.

Parameters
codeError code value
Returns
Error message

Implements kcenon::common::error_category.

Definition at line 226 of file error_category.h.

226 {
227 switch (code) {
228 case success: return "Success";
229 case unknown_error: return "Unknown error";
230 case invalid_argument: return "Invalid argument";
231 case not_found: return "Not found";
232 case permission_denied: return "Permission denied";
233 case timeout: return "Operation timed out";
234 case cancelled: return "Operation was cancelled";
235 case not_initialized: return "Not initialized";
236 case already_exists: return "Already exists";
237 case out_of_memory: return "Out of memory";
238 case io_error: return "I/O error";
239 case operation_not_supported: return "Operation not supported";
240 case internal_error: return "Internal error";
241 default: return "Unknown common error (code: " + std::to_string(code) + ")";
242 }
243 }

References already_exists, cancelled, internal_error, invalid_argument, io_error, not_found, not_initialized, operation_not_supported, out_of_memory, permission_denied, success, timeout, and unknown_error.

◆ name()

std::string_view kcenon::common::common_error_category::name ( ) const
inlineoverridevirtualnoexcept

Returns the category name.

Returns
"common"

Implements kcenon::common::error_category.

Definition at line 217 of file error_category.h.

217 {
218 return "common";
219 }

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