NeoN
A framework for CFD software
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Functions
error.hpp File Reference
#include <cstdlib>
#include <exception>
#include <iostream>
#include <string>
#include <sstream>
#include "info.hpp"

Go to the source code of this file.

Classes

class  NeoN::NeoNException
 Custom exception class for NeoN. More...
 

Namespaces

namespace  NeoN
 Integer types used throughout NeoN.
 
namespace  NeoN::Logging
 
namespace  NeoN::Logging::detail
 

Macros

#define NF_ERROR_MESSAGE(message)    "Error: " << message << "\nFile: " << __FILE__ << "\nLine: " << __LINE__ << "\n"
 Builds an error message fragment with the message, file, and line. The stack trace is emitted separately by logFatal()/terminate().
 
#define NF_ERROR_EXIT(message)    NeoN::Logging::detail::logFatal((std::stringstream() << NF_ERROR_MESSAGE(message)).str())
 Macro for printing an error message and aborting the program.
 
#define NF_THROW(message)    throw NeoN::NeoNException((std::stringstream() << NF_ERROR_MESSAGE(std::string(message))).str())
 Macro for throwing a NeoNException with the specified error message.
 
#define NF_ASSERT(condition, message)
 Macro for asserting a condition and printing an error message if the condition is false.
 
#define NF_ASSERT_THROW(condition, message)
 Macro for asserting a condition and throwing a NeoNException if the condition is false.
 
#define NF_DEBUG_ASSERT(condition, message)   ((void)0)
 Macro for asserting a condition and printing an error message if the condition is false (only in debug mode).
 
#define NF_DEBUG_ASSERT_THROW(condition, message)   ((void)0)
 Macro for asserting a condition and throwing a NeoNException if the condition is false (only in debug mode).
 
#define NF_ASSERT_EQUAL(a, b)   NF_ASSERT(a == b, "Expected " << b << ", got " << a)
 Macro for asserting that two values are equal and printing an error message if they are not.
 
#define NF_DEBUG_ASSERT_EQUAL(a, b)   NF_DEBUG_ASSERT(a == b, "Expected " << b << ", got " << a)
 Macro for asserting that two values are equal and printing an error message if they are not (only in debug mode).
 
#define NF_ASSERT_EQUAL_THROW(a, b)   NF_ASSERT_THROW(a == b, "Expected " << b << ", got " << a)
 Macro for asserting that two values are equal and throwing a NeoNException if they are not.
 
#define NF_DEBUG_ASSERT_EQUAL_THROW(a, b)    NF_DEBUG_ASSERT_THROW(a == b, "Expected " << b << ", got " << a)
 Macro for asserting that two values are equal and throwing a NeoNException if they are not (only in debug mode).
 

Functions

void NeoN::Logging::detail::logFatal (const std::string &message)
 

Macro Definition Documentation

◆ NF_ASSERT

#define NF_ASSERT (   condition,
  message 
)
Value:
do \
{ \
if (!(condition)) [[unlikely]] \
{ \
NF_ERROR_EXIT( \
"Assertion `" #condition " in " << __FILE__ << ":" << __LINE__ \
<< "` failed.\n " << message \
); \
} \
} \
while (false)

Macro for asserting a condition and printing an error message if the condition is false.

This macro checks the specified condition and, if it evaluates to false, prints an error message to the standard error stream, including the current file name and current line number, and then calls std::abort() to terminate the program.

Parameters
conditionThe condition to be checked.
messageThe error message to be printed if the condition is false.

Definition at line 118 of file error.hpp.

◆ NF_ASSERT_EQUAL

#define NF_ASSERT_EQUAL (   a,
 
)    NF_ASSERT(a == b, "Expected " << b << ", got " << a)

Macro for asserting that two values are equal and printing an error message if they are not.

This macro checks that the two specified values are equal and, if they are not, prints an error message to the standard error stream, including the expected and actual values, the current file name, and the current line number, and then calls std::abort() to terminate the program.

Parameters
aThe actual value to be compared.
bThe expected value to be compared.

Definition at line 218 of file error.hpp.

◆ NF_ASSERT_EQUAL_THROW

#define NF_ASSERT_EQUAL_THROW (   a,
 
)    NF_ASSERT_THROW(a == b, "Expected " << b << ", got " << a)

Macro for asserting that two values are equal and throwing a NeoNException if they are not.

This macro checks that the two specified values are equal and, if they are not, constructs a std::stringstream to concatenate the expected and actual values with the current file name and current line number, and then throws a NeoNException with the resulting string as the error message.

Parameters
aThe actual value to be compared.
bThe expected value to be compared.

Definition at line 245 of file error.hpp.

◆ NF_ASSERT_THROW

#define NF_ASSERT_THROW (   condition,
  message 
)
Value:
do \
{ \
if (!(condition)) [[unlikely]] \
{ \
NF_THROW("Assertion `" #condition "` failed.\n " << message); \
} \
} \
while (false)

Macro for asserting a condition and throwing a NeoNException if the condition is false.

This macro checks the specified condition and, if it evaluates to false, constructs a std::stringstream to concatenate the specified error message with the current file name and current line number, and then throws a NeoNException with the resulting string as the error message.

Parameters
conditionThe condition to be checked.
messageThe error message to be included in the exception if the condition is false.

Definition at line 144 of file error.hpp.

◆ NF_DEBUG_ASSERT

#define NF_DEBUG_ASSERT (   condition,
  message 
)    ((void)0)

Macro for asserting a condition and printing an error message if the condition is false (only in debug mode).

This macro does nothing in release mode.

Parameters
conditionThe condition to be checked.
messageThe error message to be printed if the condition is false.

Definition at line 190 of file error.hpp.

◆ NF_DEBUG_ASSERT_EQUAL

#define NF_DEBUG_ASSERT_EQUAL (   a,
 
)    NF_DEBUG_ASSERT(a == b, "Expected " << b << ", got " << a)

Macro for asserting that two values are equal and printing an error message if they are not (only in debug mode).

This macro is equivalent to NF_ASSERT_EQUAL in debug mode.

Parameters
aThe actual value to be compared.
bThe expected value to be compared.

Definition at line 230 of file error.hpp.

◆ NF_DEBUG_ASSERT_EQUAL_THROW

#define NF_DEBUG_ASSERT_EQUAL_THROW (   a,
 
)     NF_DEBUG_ASSERT_THROW(a == b, "Expected " << b << ", got " << a)

Macro for asserting that two values are equal and throwing a NeoNException if they are not (only in debug mode).

This macro is equivalent to NF_ASSERT_EQUAL_THROW in debug mode.

Parameters
aThe actual value to be compared.
bThe expected value to be compared.

Definition at line 257 of file error.hpp.

◆ NF_DEBUG_ASSERT_THROW

#define NF_DEBUG_ASSERT_THROW (   condition,
  message 
)    ((void)0)

Macro for asserting a condition and throwing a NeoNException if the condition is false (only in debug mode).

This macro does nothing in release mode.

Parameters
conditionThe condition to be checked.
messageThe error message to be included in the exception if the condition is false.

Definition at line 203 of file error.hpp.

◆ NF_ERROR_EXIT

#define NF_ERROR_EXIT (   message)     NeoN::Logging::detail::logFatal((std::stringstream() << NF_ERROR_MESSAGE(message)).str())

Macro for printing an error message and aborting the program.

This macro prints the specified error message to the standard error stream, including the current file name and current line number, and then calls std::abort() to terminate the program.

Parameters
messageThe error message to be printed.

Definition at line 90 of file error.hpp.

◆ NF_ERROR_MESSAGE

#define NF_ERROR_MESSAGE (   message)     "Error: " << message << "\nFile: " << __FILE__ << "\nLine: " << __LINE__ << "\n"

Builds an error message fragment with the message, file, and line. The stack trace is emitted separately by logFatal()/terminate().

Parameters
messageThe error message to be included in the generated message.

Definition at line 74 of file error.hpp.

◆ NF_THROW

#define NF_THROW (   message)     throw NeoN::NeoNException((std::stringstream() << NF_ERROR_MESSAGE(std::string(message))).str())

Macro for throwing a NeoNException with the specified error message.

This macro constructs a std::stringstream to concatenate the specified error message with the current file name and current line number, and then throws a NeoNException with the resulting string as the error message.

Parameters
messageThe error message to be included in the exception.

Definition at line 103 of file error.hpp.