132# include <type_traits>
137# if defined(__GNUC__) || defined(__clang__)
138# define AH_ERROR_COLD [[gnu::cold, gnu::noinline]]
139# elif defined(_MSC_VER)
140# define AH_ERROR_COLD __declspec(noinline)
142# define AH_ERROR_COLD
151 namespace error_detail
207 [[nodiscard]] std::ostringstream &&
stream() noexcept
209 return static_cast<std::ostringstream &&
>(*stream_);
245 if (
const auto * oss =
dynamic_cast<const std::ostringstream *
>(&s))
248 if (
const auto * ss =
dynamic_cast<const std::stringstream *
>(&s))
251 throw E(
"Unknown stream type in Aleph::ExceptionBuilder");
263#define AH_ERRORS_JOIN_(a, b) a ## b
264#define AH_ERRORS_JOIN(a, b) AH_ERRORS_JOIN_(a, b)
265#define AH_WARNING_ONCE AH_ERRORS_JOIN(ah_warning_once_, __LINE__)
270# if defined(__clang__)
271# define AH_ERROR_UNLIKELY
273# define AH_ERROR_UNLIKELY [[unlikely]]
288#define ah_warning_unless(out, C) \
289 for (bool AH_WARNING_ONCE = not (C); AH_WARNING_ONCE; \
290 AH_WARNING_ONCE = false) \
291 [[unlikely]](out) << "WARNING (" << __FILE__ << ":" << __LINE__ << ") | "
305#define ah_warning_if(out, C) \
306 for (bool AH_WARNING_ONCE = (C) ? true : false; AH_WARNING_ONCE; \
307 AH_WARNING_ONCE = false) \
308 [[unlikely]](out) << "WARNING (" << __FILE__ << ":" << __LINE__ << ") | "
321#define ah_warning(out) \
322 (out) << "WARNING (" << __FILE__ << ":" << __LINE__ << ") | "
340#define ah_range_error_unless(C) \
341 while (not (C)) AH_ERROR_UNLIKELY \
342 Aleph::ExceptionBuilder<std::range_error>() <<= \
343 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
356#define ah_range_error_if(C) \
357 while ((C) ? true : false) AH_ERROR_UNLIKELY \
358 Aleph::ExceptionBuilder<std::range_error>() <<= \
359 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
372#define ah_range_error() \
373 Aleph::ExceptionBuilder<std::range_error>() <<= \
374 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
376#define ah_range_error_if_constexpr(C) \
377 while (std::bool_constant<(C) ? true : false>::value) \
380#define ah_range_error_unless_constexpr(C) \
381 while (std::bool_constant<not (C)>::value) \
399#define ah_runtime_error_unless(C) \
400 while (not (C)) AH_ERROR_UNLIKELY \
401 Aleph::ExceptionBuilder<std::runtime_error>() <<= \
402 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
415#define ah_runtime_error_if(C) \
416 while ((C) ? true : false) AH_ERROR_UNLIKELY \
417 Aleph::ExceptionBuilder<std::runtime_error>() <<= \
418 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
431#define ah_runtime_error() \
432 Aleph::ExceptionBuilder<std::runtime_error>() <<= \
433 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
435#define ah_runtime_error_if_constexpr(C) \
436 while (std::bool_constant<(C) ? true : false>::value) \
439#define ah_runtime_error_unless_constexpr(C) \
440 while (std::bool_constant<not (C)>::value) \
458#define ah_logic_error_unless(C) \
459 while (not (C)) AH_ERROR_UNLIKELY \
460 Aleph::ExceptionBuilder<std::logic_error>() <<= \
461 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
474#define ah_logic_error_if(C) \
475 while ((C) ? true : false) AH_ERROR_UNLIKELY \
476 Aleph::ExceptionBuilder<std::logic_error>() <<= \
477 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
490#define ah_logic_error() \
491 Aleph::ExceptionBuilder<std::logic_error>() <<= \
492 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
494#define ah_logic_error_if_constexpr(C) \
495 while (std::bool_constant<(C) ? true : false>::value) \
498#define ah_logic_error_unless_constexpr(C) \
499 while (std::bool_constant<not (C)>::value) \
517#define ah_underflow_error_if(C) \
518 while ((C) ? true : false) AH_ERROR_UNLIKELY \
519 Aleph::ExceptionBuilder<std::underflow_error>() <<= \
520 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
533#define ah_underflow_error_unless(C) \
534 while (not (C)) AH_ERROR_UNLIKELY \
535 Aleph::ExceptionBuilder<std::underflow_error>() <<= \
536 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
549#define ah_underflow_error() \
550 Aleph::ExceptionBuilder<std::underflow_error>() <<= \
551 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
553#define ah_underflow_error_if_constexpr(C) \
554 while (std::bool_constant<(C) ? true : false>::value) \
557#define ah_underflow_error_unless_constexpr(C) \
558 while (std::bool_constant<not (C)>::value) \
570#define ah_bad_alloc() \
571 do { [[unlikely]] throw std::bad_alloc(); } while (false)
578#define ah_bad_alloc_if(C) \
579 do { if ((C) ? true : false) [[unlikely]] throw std::bad_alloc(); } \
587#define ah_bad_alloc_unless(C) \
588 do { if (!(C)) [[unlikely]] throw std::bad_alloc(); } while (false)
590#define ah_bad_alloc_if_constexpr(C) \
591 do { if constexpr (C) throw std::bad_alloc(); } while (false)
593#define ah_bad_alloc_unless_constexpr(C) \
594 do { if constexpr (not (C)) throw std::bad_alloc(); } while (false)
611#define ah_overflow_error_if(C) \
612 while ((C) ? true : false) AH_ERROR_UNLIKELY \
613 Aleph::ExceptionBuilder<std::overflow_error>() <<= \
614 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
627#define ah_overflow_error_unless(C) \
628 while (not (C)) AH_ERROR_UNLIKELY \
629 Aleph::ExceptionBuilder<std::overflow_error>() <<= \
630 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
643#define ah_overflow_error() \
644 Aleph::ExceptionBuilder<std::overflow_error>() <<= \
645 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
647#define ah_overflow_error_if_constexpr(C) \
648 while (std::bool_constant<(C) ? true : false>::value) \
651#define ah_overflow_error_unless_constexpr(C) \
652 while (std::bool_constant<not (C)>::value) \
670#define ah_domain_error_if(C) \
671 while ((C) ? true : false) AH_ERROR_UNLIKELY \
672 Aleph::ExceptionBuilder<std::domain_error>() <<= \
673 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
686#define ah_domain_error_unless(C) \
687 while (not (C)) AH_ERROR_UNLIKELY \
688 Aleph::ExceptionBuilder<std::domain_error>() <<= \
689 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
702#define ah_domain_error() \
703 Aleph::ExceptionBuilder<std::domain_error>() <<= \
704 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
705#define ah_domain_error_if_constexpr(C) \
706 while (std::bool_constant<(C) ? true : false>::value) \
708#define ah_domain_error_unless_constexpr(C) \
709 while (std::bool_constant<not (C)>::value) \
727#define ah_out_of_range_error_if(C) \
728 while ((C) ? true : false) AH_ERROR_UNLIKELY \
729 Aleph::ExceptionBuilder<std::out_of_range>() <<= \
730 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
743#define ah_out_of_range_error_unless(C) \
744 while (not (C)) AH_ERROR_UNLIKELY \
745 Aleph::ExceptionBuilder<std::out_of_range>() <<= \
746 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
759#define ah_out_of_range_error() \
760 Aleph::ExceptionBuilder<std::out_of_range>() <<= \
761 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
763#define ah_out_of_range_error_if_constexpr(C) \
764 while (std::bool_constant<(C) ? true : false>::value) \
765 ah_out_of_range_error()
767#define ah_out_of_range_error_unless_constexpr(C) \
768 while (std::bool_constant<not (C)>::value) \
769 ah_out_of_range_error()
787#define ah_invalid_argument_if(C) \
788 while ((C) ? true : false) AH_ERROR_UNLIKELY \
789 Aleph::ExceptionBuilder<std::invalid_argument>() <<= \
790 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
803#define ah_invalid_argument_unless(C) \
804 while (not (C)) AH_ERROR_UNLIKELY \
805 Aleph::ExceptionBuilder<std::invalid_argument>() <<= \
806 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
819#define ah_invalid_argument() \
820 Aleph::ExceptionBuilder<std::invalid_argument>() <<= \
821 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
823#define ah_invalid_argument_if_constexpr(C) \
824 while (std::bool_constant<(C) ? true : false>::value) \
825 ah_invalid_argument()
827#define ah_invalid_argument_unless_constexpr(C) \
828 while (std::bool_constant<not (C)>::value) \
829 ah_invalid_argument()
846#define ah_length_error_if(C) \
847 while ((C) ? true : false) AH_ERROR_UNLIKELY \
848 Aleph::ExceptionBuilder<std::length_error>() <<= \
849 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
862#define ah_length_error_unless(C) \
863 while (not (C)) AH_ERROR_UNLIKELY \
864 Aleph::ExceptionBuilder<std::length_error>() <<= \
865 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
878#define ah_length_error() \
879 Aleph::ExceptionBuilder<std::length_error>() <<= \
880 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
882#define ah_length_error_if_constexpr(C) \
883 while (std::bool_constant<(C) ? true : false>::value) \
886#define ah_length_error_unless_constexpr(C) \
887 while (std::bool_constant<not (C)>::value) \
907#define ah_fatal_error() \
908 Aleph::ExceptionBuilder<std::runtime_error>() <<= \
909 Aleph::error_detail::Message_Stream(__FILE__, __LINE__).stream()
The stream of the message of a macro that throws.
std::ostringstream && stream() noexcept
The stream, as the temporary stream of a macro was.
Message_Stream(const char *file, const int line)
Makes the stream and writes in it the place of the error.
Message_Stream & operator=(const Message_Stream &)=delete
A message has one stream: it is not assigned.
~Message_Stream()
Frees the stream.
std::ostringstream * stream_
Message_Stream(const Message_Stream &)=delete
A message has one stream: it is not copied.
Main namespace for Aleph-w library functions.
Exception constructor with formatted message.
int operator<<=(const std::ostream &s)
Operator that throws the exception with the constructed message.