Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
ah-errors.H File Reference

Exception handling system with formatted messages for Aleph-w. More...

#include <stdexcept>
#include <sstream>
#include <type_traits>
Include dependency graph for ah-errors.H:

Go to the source code of this file.

Classes

class  Aleph::error_detail::Message_Stream
 The stream of the message of a macro that throws. More...
 
struct  Aleph::ExceptionBuilder< E >
 Exception constructor with formatted message. More...
 

Namespaces

namespace  Aleph
 Main namespace for Aleph-w library functions.
 
namespace  Aleph::error_detail
 What the macros that throw need besides ExceptionBuilder.
 

Macros

#define AH_ERROR_COLD
 
#define AH_ERRORS_JOIN_(a, b)   a ## b
 
#define AH_ERRORS_JOIN(a, b)   AH_ERRORS_JOIN_(a, b)
 
#define AH_WARNING_ONCE   AH_ERRORS_JOIN(ah_warning_once_, __LINE__)
 
#define AH_ERROR_UNLIKELY   [[unlikely]]
 
#define ah_warning_unless(out, C)
 Emits a warning to a stream if the condition does NOT hold.
 
#define ah_warning_if(out, C)
 Emits a warning to a stream if the condition holds.
 
#define ah_warning(out)    (out) << "WARNING (" << __FILE__ << ":" << __LINE__ << ") | "
 Emits an unconditional warning to a stream.
 
#define ah_range_error_unless(C)
 Throws std::range_error if condition does NOT hold.
 
#define ah_range_error_if(C)
 Throws std::range_error if condition holds.
 
#define ah_range_error()
 Throws std::range_error unconditionally.
 
#define ah_range_error_if_constexpr(C)
 
#define ah_range_error_unless_constexpr(C)
 
#define ah_runtime_error_unless(C)
 Throws std::runtime_error if condition does NOT hold.
 
#define ah_runtime_error_if(C)
 Throws std::runtime_error if condition holds.
 
#define ah_runtime_error()
 Throws std::runtime_error unconditionally.
 
#define ah_runtime_error_if_constexpr(C)
 
#define ah_runtime_error_unless_constexpr(C)
 
#define ah_logic_error_unless(C)
 Throws std::logic_error if condition does NOT hold.
 
#define ah_logic_error_if(C)
 Throws std::logic_error if condition holds.
 
#define ah_logic_error()
 Throws std::logic_error unconditionally.
 
#define ah_logic_error_if_constexpr(C)
 
#define ah_logic_error_unless_constexpr(C)
 
#define ah_underflow_error_if(C)
 Throws std::underflow_error if condition holds.
 
#define ah_underflow_error_unless(C)
 Throws std::underflow_error if condition does NOT hold.
 
#define ah_underflow_error()
 Throws std::underflow_error unconditionally.
 
#define ah_underflow_error_if_constexpr(C)
 
#define ah_underflow_error_unless_constexpr(C)
 
#define ah_bad_alloc()    do { [[unlikely]] throw std::bad_alloc(); } while (false)
 Throws std::bad_alloc unconditionally (no message stream)
 
#define ah_bad_alloc_if(C)
 Throws std::bad_alloc if condition holds.
 
#define ah_bad_alloc_unless(C)    do { if (!(C)) [[unlikely]] throw std::bad_alloc(); } while (false)
 Throws std::bad_alloc if condition does NOT hold.
 
#define ah_bad_alloc_if_constexpr(C)    do { if constexpr (C) throw std::bad_alloc(); } while (false)
 
#define ah_bad_alloc_unless_constexpr(C)    do { if constexpr (not (C)) throw std::bad_alloc(); } while (false)
 
#define ah_overflow_error_if(C)
 Throws std::overflow_error if condition holds.
 
#define ah_overflow_error_unless(C)
 Throws std::overflow_error if condition does NOT hold.
 
#define ah_overflow_error()
 Throws std::overflow_error unconditionally.
 
#define ah_overflow_error_if_constexpr(C)
 
#define ah_overflow_error_unless_constexpr(C)
 
#define ah_domain_error_if(C)
 Throws std::domain_error if condition holds.
 
#define ah_domain_error_unless(C)
 Throws std::domain_error if condition does NOT hold.
 
#define ah_domain_error()
 Throws std::domain_error unconditionally.
 
#define ah_domain_error_if_constexpr(C)
 
#define ah_domain_error_unless_constexpr(C)
 
#define ah_out_of_range_error_if(C)
 Throws std::out_of_range if condition holds.
 
#define ah_out_of_range_error_unless(C)
 Throws std::out_of_range if condition does NOT hold.
 
#define ah_out_of_range_error()
 Throws std::out_of_range unconditionally.
 
#define ah_out_of_range_error_if_constexpr(C)
 
#define ah_out_of_range_error_unless_constexpr(C)
 
#define ah_invalid_argument_if(C)
 Throws std::invalid_argument if condition holds.
 
#define ah_invalid_argument_unless(C)
 Throws std::invalid_argument if condition does NOT hold.
 
#define ah_invalid_argument()
 Throws std::invalid_argument unconditionally.
 
#define ah_invalid_argument_if_constexpr(C)
 
#define ah_invalid_argument_unless_constexpr(C)
 
#define ah_length_error_if(C)
 Throws std::length_error if condition holds.
 
#define ah_length_error_unless(C)
 Throws std::length_error if condition does NOT hold.
 
#define ah_length_error()
 Throws std::length_error unconditionally.
 
#define ah_length_error_if_constexpr(C)
 
#define ah_length_error_unless_constexpr(C)
 
#define ah_fatal_error()
 Throws an unconditional std::runtime_error (fatal error)
 

Detailed Description

Exception handling system with formatted messages for Aleph-w.

This file provides a complete set of macros to throw standard C++ exceptions with custom messages and automatic code location tracking.

Main Features

  • Macros for all standard C++ exceptions
  • Formatted error messages using stream operator <<
  • Automatic location tracking (file:line) in each exception
  • Optimization with [[unlikely]] for error cases
  • Conditional versions (_if, _unless) for each exception type

Available Exception Types

  • range_error: Values outside valid range
  • runtime_error: Errors detected at runtime
  • logic_error: Program logic errors (bugs)
  • underflow_error: Arithmetic underflow
  • overflow_error: Arithmetic overflow
  • domain_error: Values outside function domain
  • out_of_range: Out of range access in containers
  • invalid_argument: Invalid arguments (most common)
  • length_error: Exceeds size limits

Usage Examples

// Validate index range
ah_out_of_range_error_if(index >= size) << "Index " << index << " out of range";
// Validate arguments
ah_invalid_argument_unless(ptr != nullptr) << "Null pointer not allowed";
// Validate mathematical operations
ah_domain_error_if(x < 0) << "sqrt requires non-negative value";
// Unrecoverable fatal error
ah_fatal_error() << "Corrupted data structure detected";
// Warnings (do not throw exception)
ah_warning_if(std::cerr, size > 1000) << "Large size may impact performance";
#define ah_out_of_range_error_if(C)
Throws std::out_of_range if condition holds.
Definition ah-errors.H:727
#define ah_fatal_error()
Throws an unconditional std::runtime_error (fatal error)
Definition ah-errors.H:907
#define ah_warning_if(out, C)
Emits a warning to a stream if the condition holds.
Definition ah-errors.H:305
#define ah_invalid_argument_unless(C)
Throws std::invalid_argument if condition does NOT hold.
Definition ah-errors.H:803
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
Definition ah-errors.H:670

Naming Convention

  • ah_TYPE_error_if(C): Throws exception if C is true
  • ah_TYPE_error_unless(C): Throws exception if C is false
  • ah_warning_if/unless: Emits warning without throwing exception

The conditional macros take no else

Every _if and _unless macro, their _constexpr forms included, expands to a loop whose statement runs at most once: a while whose statement throws, a for of one iteration for the warnings, and do { ... } while (false) for the forms of ah_bad_alloc. A loop takes no else, so an else written after an invocation belongs to the if around it, and one with no if around it does not compile:

if (checked)
ah_domain_error_if(x < 0) << "x is negative";
else // runs when not checked
use(x);

The condition is evaluated once, and it converts to bool as that of an if does, so a scoped enumeration does not; it must be an expression, not a declaration as in if (auto e = f()). The _constexpr forms require a constant condition, and their message is compiled even where the condition is false, so it must compile for every instantiation. A message whose last << does not give back a stream does not compile.

The stream of a message is out of the frame

A macro that throws writes its message in a std::ostringstream, with the insertions of its caller, as it always did. That stream does not live in the frame of the function that checks: an object of one pointer, error_detail::Message_Stream, makes it when the macro throws and frees it when the exception leaves. A stream in that frame, 376 bytes with libstdc++ on x86-64, kept GCC from inlining a checked access as Array::operator[], and each access was a call.

The message does not change. Its items go into a stream of the same type, in their order and when they are evaluated, and only if the macro throws. Out of the message, two things do change:

  • The stream is allocated: a macro that throws asks for one block of memory more. Without memory for it, the macro throws std::bad_alloc in the place of its exception, and does not evaluate its items.
  • The place of the error, (file:line) |, is written by the library, with the inserters of the standard library. An overload of << for an rvalue std::ostringstream that is visible where a macro is used takes the items of that use, and no longer the place.
Author
Leandro Rabindranath Leon
Date
2002-2025 *

Definition in file ah-errors.H.

Macro Definition Documentation

◆ ah_bad_alloc

#define ah_bad_alloc ( )     do { [[unlikely]] throw std::bad_alloc(); } while (false)

Throws std::bad_alloc unconditionally (no message stream)

Definition at line 570 of file ah-errors.H.

◆ ah_bad_alloc_if

#define ah_bad_alloc_if (   C)
Value:
do { if ((C) ? true : false) [[unlikely]] throw std::bad_alloc(); } \
while (false)
STL namespace.

Throws std::bad_alloc if condition holds.

Definition at line 578 of file ah-errors.H.

◆ ah_bad_alloc_if_constexpr

#define ah_bad_alloc_if_constexpr (   C)     do { if constexpr (C) throw std::bad_alloc(); } while (false)

Definition at line 590 of file ah-errors.H.

◆ ah_bad_alloc_unless

#define ah_bad_alloc_unless (   C)     do { if (!(C)) [[unlikely]] throw std::bad_alloc(); } while (false)

Throws std::bad_alloc if condition does NOT hold.

Definition at line 587 of file ah-errors.H.

◆ ah_bad_alloc_unless_constexpr

#define ah_bad_alloc_unless_constexpr (   C)     do { if constexpr (not (C)) throw std::bad_alloc(); } while (false)

Definition at line 593 of file ah-errors.H.

◆ ah_domain_error

#define ah_domain_error ( )
Value:
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
Exception constructor with formatted message.
Definition ah-errors.H:226

Throws std::domain_error unconditionally.

Exceptions
std::domain_erroralways

Throws a domain_error without evaluating any condition. Use when you need to throw directly.

ah_domain_error() << "Value outside function domain";
#define ah_domain_error()
Throws std::domain_error unconditionally.
Definition ah-errors.H:702

*

Definition at line 702 of file ah-errors.H.

◆ ah_domain_error_if

#define ah_domain_error_if (   C)
Value:
while ((C) ? true : false) AH_ERROR_UNLIKELY \
Aleph::ExceptionBuilder<std::domain_error>() <<= \
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
#define AH_ERROR_UNLIKELY
Definition ah-errors.H:273
Main namespace for Aleph-w library functions.

Throws std::domain_error if condition holds.

Parameters
CCondition to evaluate
Exceptions
std::domain_errorif C is true

Useful when a value is outside the valid domain of a function.

ah_domain_error_if(x < 0) << "sqrt requires non-negative input";

*

Definition at line 670 of file ah-errors.H.

◆ ah_domain_error_if_constexpr

#define ah_domain_error_if_constexpr (   C)
Value:
while (std::bool_constant<(C) ? true : false>::value) \
size_t size_t int32_t value
Definition ca-c-api.h:116

Definition at line 705 of file ah-errors.H.

◆ ah_domain_error_unless

#define ah_domain_error_unless (   C)
Value:
while (not (C)) AH_ERROR_UNLIKELY \
Aleph::ExceptionBuilder<std::domain_error>() <<= \
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws std::domain_error if condition does NOT hold.

Parameters
CCondition to evaluate
Exceptions
std::domain_errorif C is false

Useful for validating that a value is in the valid domain.

ah_domain_error_unless(divisor != 0) << "Division by zero";
#define ah_domain_error_unless(C)
Throws std::domain_error if condition does NOT hold.
Definition ah-errors.H:686

*

Definition at line 686 of file ah-errors.H.

◆ ah_domain_error_unless_constexpr

#define ah_domain_error_unless_constexpr (   C)
Value:
while (std::bool_constant<not (C)>::value) \
ah_domain_error()

Definition at line 708 of file ah-errors.H.

◆ AH_ERROR_COLD

#define AH_ERROR_COLD

Definition at line 142 of file ah-errors.H.

◆ AH_ERROR_UNLIKELY

#define AH_ERROR_UNLIKELY   [[unlikely]]

Definition at line 273 of file ah-errors.H.

◆ AH_ERRORS_JOIN

#define AH_ERRORS_JOIN (   a,
  b 
)    AH_ERRORS_JOIN_(a, b)

Definition at line 264 of file ah-errors.H.

◆ AH_ERRORS_JOIN_

#define AH_ERRORS_JOIN_ (   a,
  b 
)    a ## b

Definition at line 263 of file ah-errors.H.

◆ ah_fatal_error

#define ah_fatal_error ( )
Value:
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws an unconditional std::runtime_error (fatal error)

Exceptions
std::runtime_erroralways

Useful for situations that should never occur or unrecoverable errors. Does not require a condition.

if (impossible_condition) {
ah_fatal_error() << "This should never happen!";
}

*

Definition at line 907 of file ah-errors.H.

◆ ah_invalid_argument

#define ah_invalid_argument ( )
Value:
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws std::invalid_argument unconditionally.

Exceptions
std::invalid_argumentalways

Throws an invalid_argument error without evaluating any condition. Use when you need to throw directly.

ah_invalid_argument() << "Invalid argument provided";
#define ah_invalid_argument()
Throws std::invalid_argument unconditionally.
Definition ah-errors.H:819

*

Definition at line 819 of file ah-errors.H.

◆ ah_invalid_argument_if

#define ah_invalid_argument_if (   C)
Value:
while ((C) ? true : false) AH_ERROR_UNLIKELY \
Aleph::ExceptionBuilder<std::invalid_argument>() <<= \
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws std::invalid_argument if condition holds.

Parameters
CCondition to evaluate
Exceptions
std::invalid_argumentif C is true

Useful for validating function arguments. Most common exception for incorrect parameter validation.

ah_invalid_argument_if(name.empty()) << "Name cannot be empty";
#define ah_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
Definition ah-errors.H:787

*

Definition at line 787 of file ah-errors.H.

◆ ah_invalid_argument_if_constexpr

#define ah_invalid_argument_if_constexpr (   C)
Value:
while (std::bool_constant<(C) ? true : false>::value) \

Definition at line 823 of file ah-errors.H.

◆ ah_invalid_argument_unless

#define ah_invalid_argument_unless (   C)
Value:
while (not (C)) AH_ERROR_UNLIKELY \
Aleph::ExceptionBuilder<std::invalid_argument>() <<= \
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws std::invalid_argument if condition does NOT hold.

Parameters
CCondition to evaluate
Exceptions
std::invalid_argumentif C is false

Useful for validating that arguments meet required conditions.

ah_invalid_argument_unless(size > 0) << "Size must be positive";

*

Definition at line 803 of file ah-errors.H.

◆ ah_invalid_argument_unless_constexpr

#define ah_invalid_argument_unless_constexpr (   C)
Value:
while (std::bool_constant<not (C)>::value) \
ah_invalid_argument()

Definition at line 827 of file ah-errors.H.

◆ ah_length_error

#define ah_length_error ( )
Value:
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws std::length_error unconditionally.

Exceptions
std::length_erroralways

Throws a length_error without evaluating any condition. Use when you need to throw directly.

ah_length_error() << "Container size limit exceeded";
#define ah_length_error()
Throws std::length_error unconditionally.
Definition ah-errors.H:878

*

Definition at line 878 of file ah-errors.H.

◆ ah_length_error_if

#define ah_length_error_if (   C)
Value:
while ((C) ? true : false) AH_ERROR_UNLIKELY \
Aleph::ExceptionBuilder<std::length_error>() <<= \
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws std::length_error if condition holds.

Parameters
CCondition to evaluate
Exceptions
std::length_errorif C is true

Useful when an operation exceeds container size limits.

ah_length_error_if(new_size > max_size()) << "Container size exceeded";
#define ah_length_error_if(C)
Throws std::length_error if condition holds.
Definition ah-errors.H:846

*

Definition at line 846 of file ah-errors.H.

◆ ah_length_error_if_constexpr

#define ah_length_error_if_constexpr (   C)
Value:
while (std::bool_constant<(C) ? true : false>::value) \

Definition at line 882 of file ah-errors.H.

◆ ah_length_error_unless

#define ah_length_error_unless (   C)
Value:
while (not (C)) AH_ERROR_UNLIKELY \
Aleph::ExceptionBuilder<std::length_error>() <<= \
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws std::length_error if condition does NOT hold.

Parameters
CCondition to evaluate
Exceptions
std::length_errorif C is false

Useful for validating that size is within allowed limits.

ah_length_error_unless(size <= max_size()) << "Size exceeds limit";
#define ah_length_error_unless(C)
Throws std::length_error if condition does NOT hold.
Definition ah-errors.H:862

*

Definition at line 862 of file ah-errors.H.

◆ ah_length_error_unless_constexpr

#define ah_length_error_unless_constexpr (   C)
Value:
while (std::bool_constant<not (C)>::value) \
ah_length_error()

Definition at line 886 of file ah-errors.H.

◆ ah_logic_error

#define ah_logic_error ( )
Value:
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws std::logic_error unconditionally.

Exceptions
std::logic_erroralways

Throws a logic_error without evaluating any condition. Use when you need to throw directly.

ah_logic_error() << "Program logic invariant violated";
#define ah_logic_error()
Throws std::logic_error unconditionally.
Definition ah-errors.H:490

*

Definition at line 490 of file ah-errors.H.

◆ ah_logic_error_if

#define ah_logic_error_if (   C)
Value:
while ((C) ? true : false) AH_ERROR_UNLIKELY \
Aleph::ExceptionBuilder<std::logic_error>() <<= \
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws std::logic_error if condition holds.

Parameters
CCondition to evaluate
Exceptions
std::logic_errorif C is true

Useful for detecting program logic errors.

ah_logic_error_if(ptr == nullptr) << "Unexpected null pointer";
#define ah_logic_error_if(C)
Throws std::logic_error if condition holds.
Definition ah-errors.H:474

*

Definition at line 474 of file ah-errors.H.

◆ ah_logic_error_if_constexpr

#define ah_logic_error_if_constexpr (   C)
Value:
while (std::bool_constant<(C) ? true : false>::value) \

Definition at line 494 of file ah-errors.H.

◆ ah_logic_error_unless

#define ah_logic_error_unless (   C)
Value:
while (not (C)) AH_ERROR_UNLIKELY \
Aleph::ExceptionBuilder<std::logic_error>() <<= \
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws std::logic_error if condition does NOT hold.

Parameters
CCondition to evaluate
Exceptions
std::logic_errorif C is false

Useful for program logic errors (bugs, violated invariants).

ah_logic_error_unless(is_valid_state()) << "Invalid object state";
#define ah_logic_error_unless(C)
Throws std::logic_error if condition does NOT hold.
Definition ah-errors.H:458

*

Definition at line 458 of file ah-errors.H.

◆ ah_logic_error_unless_constexpr

#define ah_logic_error_unless_constexpr (   C)
Value:
while (std::bool_constant<not (C)>::value) \
ah_logic_error()

Definition at line 498 of file ah-errors.H.

◆ ah_out_of_range_error

#define ah_out_of_range_error ( )
Value:
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws std::out_of_range unconditionally.

Exceptions
std::out_of_rangealways

Throws an out_of_range error without evaluating any condition. Use when you need to throw directly.

ah_out_of_range_error() << "Index out of bounds";
#define ah_out_of_range_error()
Throws std::out_of_range unconditionally.
Definition ah-errors.H:759

*

Definition at line 759 of file ah-errors.H.

◆ ah_out_of_range_error_if

#define ah_out_of_range_error_if (   C)
Value:
while ((C) ? true : false) AH_ERROR_UNLIKELY \
Aleph::ExceptionBuilder<std::out_of_range>() <<= \
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws std::out_of_range if condition holds.

Parameters
CCondition to evaluate
Exceptions
std::out_of_rangeif C is true

Useful for out of range element access in containers.

ah_out_of_range_error_if(index >= size) << "Index out of bounds";

*

Definition at line 727 of file ah-errors.H.

◆ ah_out_of_range_error_if_constexpr

#define ah_out_of_range_error_if_constexpr (   C)
Value:
while (std::bool_constant<(C) ? true : false>::value) \

Definition at line 763 of file ah-errors.H.

◆ ah_out_of_range_error_unless

#define ah_out_of_range_error_unless (   C)
Value:
while (not (C)) AH_ERROR_UNLIKELY \
Aleph::ExceptionBuilder<std::out_of_range>() <<= \
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws std::out_of_range if condition does NOT hold.

Parameters
CCondition to evaluate
Exceptions
std::out_of_rangeif C is false

Useful for validating valid index access.

ah_out_of_range_error_unless(index < size) << "Invalid index";
#define ah_out_of_range_error_unless(C)
Throws std::out_of_range if condition does NOT hold.
Definition ah-errors.H:743

*

Definition at line 743 of file ah-errors.H.

◆ ah_out_of_range_error_unless_constexpr

#define ah_out_of_range_error_unless_constexpr (   C)
Value:
while (std::bool_constant<not (C)>::value) \
ah_out_of_range_error()

Definition at line 767 of file ah-errors.H.

◆ ah_overflow_error

#define ah_overflow_error ( )
Value:
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws std::overflow_error unconditionally.

Exceptions
std::overflow_erroralways

Throws an overflow_error without evaluating any condition. Use when you need to throw directly.

ah_overflow_error() << "Arithmetic overflow detected";
#define ah_overflow_error()
Throws std::overflow_error unconditionally.
Definition ah-errors.H:643

*

Definition at line 643 of file ah-errors.H.

◆ ah_overflow_error_if

#define ah_overflow_error_if (   C)
Value:
while ((C) ? true : false) AH_ERROR_UNLIKELY \
Aleph::ExceptionBuilder<std::overflow_error>() <<= \
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws std::overflow_error if condition holds.

Parameters
CCondition to evaluate
Exceptions
std::overflow_errorif C is true

Useful for arithmetic operations that result in overflow.

ah_overflow_error_if(result > max_value) << "Arithmetic overflow";
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
Definition ah-errors.H:611

*

Definition at line 611 of file ah-errors.H.

◆ ah_overflow_error_if_constexpr

#define ah_overflow_error_if_constexpr (   C)
Value:
while (std::bool_constant<(C) ? true : false>::value) \

Definition at line 647 of file ah-errors.H.

◆ ah_overflow_error_unless

#define ah_overflow_error_unless (   C)
Value:
while (not (C)) AH_ERROR_UNLIKELY \
Aleph::ExceptionBuilder<std::overflow_error>() <<= \
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws std::overflow_error if condition does NOT hold.

Parameters
CCondition to evaluate
Exceptions
std::overflow_errorif C is false

Useful for validating absence of arithmetic overflow.

ah_overflow_error_unless(value <= max_limit) << "Value too large";
#define ah_overflow_error_unless(C)
Throws std::overflow_error if condition does NOT hold.
Definition ah-errors.H:627

*

Definition at line 627 of file ah-errors.H.

◆ ah_overflow_error_unless_constexpr

#define ah_overflow_error_unless_constexpr (   C)
Value:
while (std::bool_constant<not (C)>::value) \
ah_overflow_error()

Definition at line 651 of file ah-errors.H.

◆ ah_range_error

#define ah_range_error ( )
Value:
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws std::range_error unconditionally.

Exceptions
std::range_erroralways

Throws a range_error without evaluating any condition. Use when you need to throw directly.

ah_range_error() << "Value is out of valid range";
#define ah_range_error()
Throws std::range_error unconditionally.
Definition ah-errors.H:372

*

Definition at line 372 of file ah-errors.H.

◆ ah_range_error_if

#define ah_range_error_if (   C)
Value:
while ((C) ? true : false) AH_ERROR_UNLIKELY \
Aleph::ExceptionBuilder<std::range_error>() <<= \
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws std::range_error if condition holds.

Parameters
CCondition to evaluate
Exceptions
std::range_errorif C is true

Useful for detecting values out of range.

ah_range_error_if(value < min || value > max) << "Value out of range";
#define ah_range_error_if(C)
Throws std::range_error if condition holds.
Definition ah-errors.H:356
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_max_function > > max(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Definition gmpfrxx.h:4188

*

Examples
blossom_example.cc.

Definition at line 356 of file ah-errors.H.

◆ ah_range_error_if_constexpr

#define ah_range_error_if_constexpr (   C)
Value:
while (std::bool_constant<(C) ? true : false>::value) \

Definition at line 376 of file ah-errors.H.

◆ ah_range_error_unless

#define ah_range_error_unless (   C)
Value:
while (not (C)) AH_ERROR_UNLIKELY \
Aleph::ExceptionBuilder<std::range_error>() <<= \
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws std::range_error if condition does NOT hold.

Parameters
CCondition to evaluate
Exceptions
std::range_errorif C is false

Useful for validating that a value is within a valid range. Error message includes location (file:line).

ah_range_error_unless(index < size) << "Index " << index << " out of range";
#define ah_range_error_unless(C)
Throws std::range_error if condition does NOT hold.
Definition ah-errors.H:340

*

Definition at line 340 of file ah-errors.H.

◆ ah_range_error_unless_constexpr

#define ah_range_error_unless_constexpr (   C)
Value:
while (std::bool_constant<not (C)>::value) \
ah_range_error()

Definition at line 380 of file ah-errors.H.

◆ ah_runtime_error

#define ah_runtime_error ( )
Value:
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws std::runtime_error unconditionally.

Exceptions
std::runtime_erroralways

Throws a runtime_error without evaluating any condition. Use when you need to throw directly.

ah_runtime_error() << "Unexpected runtime error occurred";
#define ah_runtime_error()
Throws std::runtime_error unconditionally.
Definition ah-errors.H:431

*

Definition at line 431 of file ah-errors.H.

◆ ah_runtime_error_if

#define ah_runtime_error_if (   C)
Value:
while ((C) ? true : false) AH_ERROR_UNLIKELY \
Aleph::ExceptionBuilder<std::runtime_error>() <<= \
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws std::runtime_error if condition holds.

Parameters
CCondition to evaluate
Exceptions
std::runtime_errorif C is true

Useful for detecting runtime error conditions.

ah_runtime_error_if(errno != 0) << "System error: " << strerror(errno);
#define ah_runtime_error_if(C)
Throws std::runtime_error if condition holds.
Definition ah-errors.H:415

*

Definition at line 415 of file ah-errors.H.

◆ ah_runtime_error_if_constexpr

#define ah_runtime_error_if_constexpr (   C)
Value:
while (std::bool_constant<(C) ? true : false>::value) \

Definition at line 435 of file ah-errors.H.

◆ ah_runtime_error_unless

#define ah_runtime_error_unless (   C)
Value:
while (not (C)) AH_ERROR_UNLIKELY \
Aleph::ExceptionBuilder<std::runtime_error>() <<= \
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws std::runtime_error if condition does NOT hold.

Parameters
CCondition to evaluate
Exceptions
std::runtime_errorif C is false

Useful for errors only detected at runtime.

ah_runtime_error_unless(file.is_open()) << "Failed to open file";
#define ah_runtime_error_unless(C)
Throws std::runtime_error if condition does NOT hold.
Definition ah-errors.H:399
ofstream file
Definition writeRb.C:51

*

Definition at line 399 of file ah-errors.H.

◆ ah_runtime_error_unless_constexpr

#define ah_runtime_error_unless_constexpr (   C)
Value:
while (std::bool_constant<not (C)>::value) \
ah_runtime_error()

Definition at line 439 of file ah-errors.H.

◆ ah_underflow_error

#define ah_underflow_error ( )
Value:
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws std::underflow_error unconditionally.

Exceptions
std::underflow_erroralways

Throws an underflow_error without evaluating any condition. Use when you need to throw directly.

ah_underflow_error() << "Arithmetic underflow detected";
#define ah_underflow_error()
Throws std::underflow_error unconditionally.
Definition ah-errors.H:549

*

Definition at line 549 of file ah-errors.H.

◆ ah_underflow_error_if

#define ah_underflow_error_if (   C)
Value:
while ((C) ? true : false) AH_ERROR_UNLIKELY \
Aleph::ExceptionBuilder<std::underflow_error>() <<= \
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws std::underflow_error if condition holds.

Parameters
CCondition to evaluate
Exceptions
std::underflow_errorif C is true

Useful for arithmetic operations that result in underflow.

ah_underflow_error_if(result < min_value) << "Arithmetic underflow";
#define ah_underflow_error_if(C)
Throws std::underflow_error if condition holds.
Definition ah-errors.H:517

*

Definition at line 517 of file ah-errors.H.

◆ ah_underflow_error_if_constexpr

#define ah_underflow_error_if_constexpr (   C)
Value:
while (std::bool_constant<(C) ? true : false>::value) \

Definition at line 553 of file ah-errors.H.

◆ ah_underflow_error_unless

#define ah_underflow_error_unless (   C)
Value:
while (not (C)) AH_ERROR_UNLIKELY \
Aleph::ExceptionBuilder<std::underflow_error>() <<= \
Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()

Throws std::underflow_error if condition does NOT hold.

Parameters
CCondition to evaluate
Exceptions
std::underflow_errorif C is false

Useful for validating absence of arithmetic underflow.

ah_underflow_error_unless(value >= min_limit) << "Value too small";
#define ah_underflow_error_unless(C)
Throws std::underflow_error if condition does NOT hold.
Definition ah-errors.H:533

*

Definition at line 533 of file ah-errors.H.

◆ ah_underflow_error_unless_constexpr

#define ah_underflow_error_unless_constexpr (   C)
Value:
while (std::bool_constant<not (C)>::value) \
ah_underflow_error()

Definition at line 557 of file ah-errors.H.

◆ ah_warning

#define ah_warning (   out)     (out) << "WARNING (" << __FILE__ << ":" << __LINE__ << ") | "

Emits an unconditional warning to a stream.

Parameters
outOutput stream where to write the warning

Writes a warning with file and line information without evaluating any condition.

ah_warning(std::cerr) << "Deprecated function called";
#define ah_warning(out)
Emits an unconditional warning to a stream.
Definition ah-errors.H:321

*

Definition at line 321 of file ah-errors.H.

◆ ah_warning_if

#define ah_warning_if (   out,
  C 
)
Value:
for (bool AH_WARNING_ONCE = (C) ? true : false; AH_WARNING_ONCE; \
AH_WARNING_ONCE = false) \
[[unlikely]](out) << "WARNING (" << __FILE__ << ":" << __LINE__ << ") | "
#define AH_WARNING_ONCE
Definition ah-errors.H:265
size_t size_t int32_t * out
Definition ca-c-api.h:120

Emits a warning to a stream if the condition holds.

Parameters
outOutput stream where to write the warning
CCondition to evaluate

If condition C is true, writes a warning message with file and line information.

ah_warning_if(std::cerr, size > MAX_SIZE) << "Size exceeds maximum";

*

Definition at line 305 of file ah-errors.H.

◆ AH_WARNING_ONCE

#define AH_WARNING_ONCE   AH_ERRORS_JOIN(ah_warning_once_, __LINE__)

Definition at line 265 of file ah-errors.H.

◆ ah_warning_unless

#define ah_warning_unless (   out,
  C 
)
Value:
for (bool AH_WARNING_ONCE = not (C); AH_WARNING_ONCE; \
AH_WARNING_ONCE = false) \
[[unlikely]](out) << "WARNING (" << __FILE__ << ":" << __LINE__ << ") | "

Emits a warning to a stream if the condition does NOT hold.

Parameters
outOutput stream where to write the warning
CCondition to evaluate

If condition C is false, writes a warning message with file and line information. Typical use with std::cerr.

ah_warning_unless(std::cerr, ptr != nullptr) << "Pointer is null";
#define ah_warning_unless(out, C)
Emits a warning to a stream if the condition does NOT hold.
Definition ah-errors.H:288

*

Definition at line 288 of file ah-errors.H.