io
C++ I/O scheduling library with asynchronous socket operations
Loading...
Searching...
No Matches
Macros
error.hpp File Reference

This file defines macros for creating compile-time error messages. More...

Go to the source code of this file.

Macros

#define IO_ERROR_HPP
 
#define IO_STRINGIFY(x)   #x
 Converts a macro argument to a string literal.
 
#define IO_TOSTRING(x)   IO_STRINGIFY(x)
 Helper macro to convert the result of a macro expansion to a string.
 
#define IO_ERROR_MESSAGE(msg)   (__FILE__ ":" IO_TOSTRING(__LINE__) ": " msg)
 Constructs a formatted error message with the file and line number.
 

Detailed Description

This file defines macros for creating compile-time error messages.

Definition in file error.hpp.

Macro Definition Documentation

◆ IO_ERROR_HPP

#define IO_ERROR_HPP

Definition at line 22 of file error.hpp.

◆ IO_ERROR_MESSAGE

#define IO_ERROR_MESSAGE (   msg)    (__FILE__ ":" IO_TOSTRING(__LINE__) ": " msg)

Constructs a formatted error message with the file and line number.

The resulting string literal is in the format "file:line: message".

Parameters
msgThe custom error message string to append.
Returns
A string literal containing the full error message.

Example

#include "error.hpp"
#include <iostream>
void some_function() {
std::cerr << IO_ERROR_MESSAGE("Something went wrong!") << std::endl;
}
// Possible output:
// /path/to/your/file.cpp:123: Something went wrong!
This file defines macros for creating compile-time error messages.
#define IO_ERROR_MESSAGE(msg)
Constructs a formatted error message with the file and line number.
Definition error.hpp:62

Definition at line 62 of file error.hpp.

◆ IO_STRINGIFY

#define IO_STRINGIFY (   x)    #x

Converts a macro argument to a string literal.

Parameters
xThe argument to stringify.

Definition at line 29 of file error.hpp.

◆ IO_TOSTRING

#define IO_TOSTRING (   x)    IO_STRINGIFY(x)

Helper macro to convert the result of a macro expansion to a string.

This is necessary to correctly stringify macros like __LINE__, which must be expanded before being converted to a string.

Parameters
xThe macro to expand and stringify.

Definition at line 39 of file error.hpp.