Compute Library
 23.11
Error.h File Reference
#include <array>
#include <string>

Go to the source code of this file.

Data Structures

class  Status
 Status class. More...
 

Namespaces

 arm_compute
 Copyright (c) 2017-2023 Arm Limited.
 

Macros

#define ARM_COMPUTE_UNUSED(...)   ::arm_compute::ignore_unused(__VA_ARGS__)
 To avoid unused variables warnings. More...
 
#define ARM_COMPUTE_CREATE_ERROR(error_code, msg)   arm_compute::create_error_msg(error_code, __func__, __FILE__, __LINE__, msg)
 Creates an error with a given message. More...
 
#define ARM_COMPUTE_CREATE_ERROR_LOC(error_code, func, file, line, msg)   arm_compute::create_error_msg(error_code, func, file, line, msg)
 Creates an error on location with a given message. More...
 
#define ARM_COMPUTE_CREATE_ERROR_LOC_VAR(error_code, func, file, line, msg, ...)
 Creates an error on location with a given message. More...
 
#define ARM_COMPUTE_RETURN_ERROR_MSG(...)
 An error is returned with the given description. More...
 
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
 Checks if a status contains an error and returns it. More...
 
#define ARM_COMPUTE_THROW_ON_ERROR(error)   error.throw_if_error();
 Checks if an error value is valid if not throws an exception with the error. More...
 
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG_VAR(cond, msg, ...)
 If the condition is true, an error is returned. More...
 
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
 If the condition is true, an error is returned. More...
 
#define ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG_VAR(cond, func, file, line, msg, ...)
 If the condition is true, an error is thrown. More...
 
#define ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(cond, func, file, line, msg)
 If the condition is true, an error is thrown. More...
 
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)   ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, #cond)
 If the condition is true, an error is returned. More...
 
#define ARM_COMPUTE_RETURN_ERROR_ON_LOC(cond, func, file, line)   ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(cond, func, file, line, #cond)
 If the condition is true, an error is returned. More...
 
#define ARM_COMPUTE_THROW_ERROR(func, file, line, msg)
 Print the given message then throw an std::runtime_error. More...
 
#define ARM_COMPUTE_THROW_ERROR_VAR(func, file, line, msg, ...)
 Print the given message then throw an std::runtime_error. More...
 
#define ARM_COMPUTE_ERROR_VAR(msg, ...)   ARM_COMPUTE_THROW_ERROR_VAR(__func__, __FILE__, __LINE__, msg, __VA_ARGS__)
 Print the given message then throw an std::runtime_error. More...
 
#define ARM_COMPUTE_ERROR(msg)   ARM_COMPUTE_THROW_ERROR(__func__, __FILE__, __LINE__, msg)
 Print the given message then throw an std::runtime_error. More...
 
#define ARM_COMPUTE_ERROR_LOC_VAR(func, file, line, msg, ...)   ARM_COMPUTE_THROW_ERROR_VAR(func, file, line, msg, __VA_ARGS__)
 Print the given message then throw an std::runtime_error. More...
 
#define ARM_COMPUTE_ERROR_LOC(func, file, line, msg)   ARM_COMPUTE_THROW_ERROR(func, file, line, msg)
 Print the given message then throw an std::runtime_error. More...
 
#define ARM_COMPUTE_EXIT_ON_MSG(cond, msg)
 If the condition is true, the given message is printed and program exits. More...
 
#define ARM_COMPUTE_EXIT_ON_MSG_VAR(cond, msg, ...)
 If the condition is true, the given message is printed and program exits. More...
 
#define ARM_COMPUTE_ERROR_THROW_ON(status)
 
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
 
#define ARM_COMPUTE_ERROR_ON_MSG_VAR(cond, msg, ...)
 
#define ARM_COMPUTE_ERROR_ON_LOC_MSG(cond, func, file, line, ...)
 
#define ARM_COMPUTE_CONST_ON_ERROR(cond, val, msg)   val
 
#define ARM_COMPUTE_ERROR_ON(cond)   ARM_COMPUTE_ERROR_ON_MSG(cond, #cond)
 If the condition is true then an error message is printed and an exception thrown. More...
 
#define ARM_COMPUTE_ERROR_ON_LOC(cond, func, file, line)   ARM_COMPUTE_ERROR_ON_LOC_MSG(cond, func, file, line, "%s", #cond)
 If the condition is true then an error message is printed and an exception thrown. More...
 
#define ARM_COMPUTE_THROW(ex)   throw(ex)
 

Enumerations

enum  ErrorCode { OK, RUNTIME_ERROR, UNSUPPORTED_EXTENSION_USE }
 Available error codes. More...
 

Functions

template<typename... T>
void ignore_unused (T &&...)
 Ignores unused arguments. More...
 
Status create_error (ErrorCode error_code, std::string msg)
 Creates an error containing the error message. More...
 
Status create_error_msg (ErrorCode error_code, const char *func, const char *file, int line, const char *msg)
 Creates an error and the error message. More...
 
void throw_error (Status err)
 Throw an std::runtime_error. More...
 

Macro Definition Documentation

◆ ARM_COMPUTE_CONST_ON_ERROR

#define ARM_COMPUTE_CONST_ON_ERROR (   cond,
  val,
  msg 
)    val

Definition at line 459 of file Error.h.

◆ ARM_COMPUTE_CREATE_ERROR

#define ARM_COMPUTE_CREATE_ERROR (   error_code,
  msg 
)    arm_compute::create_error_msg(error_code, __func__, __FILE__, __LINE__, msg)

Creates an error with a given message.

Parameters
[in]error_codeError code.
[in]msgMessage to encapsulate.

Definition at line 158 of file Error.h.

◆ ARM_COMPUTE_CREATE_ERROR_LOC

#define ARM_COMPUTE_CREATE_ERROR_LOC (   error_code,
  func,
  file,
  line,
  msg 
)    arm_compute::create_error_msg(error_code, func, file, line, msg)

Creates an error on location with a given message.

Parameters
[in]error_codeError code.
[in]funcFunction in which the error occurred.
[in]fileFile in which the error occurred.
[in]lineLine in which the error occurred.
[in]msgMessage to display before abandoning.

Definition at line 169 of file Error.h.

◆ ARM_COMPUTE_CREATE_ERROR_LOC_VAR

#define ARM_COMPUTE_CREATE_ERROR_LOC_VAR (   error_code,
  func,
  file,
  line,
  msg,
  ... 
)
Value:
do \
{ \
std::array<char, 512> out{0}; \
int offset = snprintf(out.data(), out.size(), "in %s %s:%d: ", func, file, line); \
snprintf(out.data() + offset, out.size() - offset, msg, __VA_ARGS__); \
arm_compute::create_error(error_code, std::string(out.data())); \
} while (false)

Creates an error on location with a given message.

Accepts a message format and a variable list of arguments matching the format description.

Parameters
[in]error_codeError code.
[in]funcFunction in which the error occurred.
[in]fileFile in which the error occurred.
[in]lineLine in which the error occurred.
[in]msgError description message format.
[in]...List of arguments matching the format description.

Definition at line 182 of file Error.h.

◆ ARM_COMPUTE_ERROR

#define ARM_COMPUTE_ERROR (   msg)    ARM_COMPUTE_THROW_ERROR(__func__, __FILE__, __LINE__, msg)

Print the given message then throw an std::runtime_error.

Parameters
[in]msgMessage to display.

Definition at line 354 of file Error.h.

◆ ARM_COMPUTE_ERROR_LOC

#define ARM_COMPUTE_ERROR_LOC (   func,
  file,
  line,
  msg 
)    ARM_COMPUTE_THROW_ERROR(func, file, line, msg)

Print the given message then throw an std::runtime_error.

Parameters
[in]funcFunction in which the error occurred.
[in]fileFile in which the error occurred.
[in]lineLine in which the error occurred.
[in]msgMessage to display.

Definition at line 375 of file Error.h.

◆ ARM_COMPUTE_ERROR_LOC_VAR

#define ARM_COMPUTE_ERROR_LOC_VAR (   func,
  file,
  line,
  msg,
  ... 
)    ARM_COMPUTE_THROW_ERROR_VAR(func, file, line, msg, __VA_ARGS__)

Print the given message then throw an std::runtime_error.

Accepts a message format and a variable list of arguments matching the format description.

Parameters
[in]funcFunction in which the error occurred.
[in]fileFile in which the error occurred.
[in]lineLine in which the error occurred.
[in]msgError description message format.
[in]...List of arguments matching the format description.

Definition at line 365 of file Error.h.

◆ ARM_COMPUTE_ERROR_ON

#define ARM_COMPUTE_ERROR_ON (   cond)    ARM_COMPUTE_ERROR_ON_MSG(cond, #cond)

If the condition is true then an error message is printed and an exception thrown.

Parameters
[in]condCondition to evaluate.

Definition at line 466 of file Error.h.

◆ ARM_COMPUTE_ERROR_ON_LOC

#define ARM_COMPUTE_ERROR_ON_LOC (   cond,
  func,
  file,
  line 
)    ARM_COMPUTE_ERROR_ON_LOC_MSG(cond, func, file, line, "%s", #cond)

If the condition is true then an error message is printed and an exception thrown.

Parameters
[in]condCondition to evaluate.
[in]funcFunction in which the error occurred.
[in]fileFile in which the error occurred.
[in]lineLine in which the error occurred.

Definition at line 475 of file Error.h.

◆ ARM_COMPUTE_ERROR_ON_LOC_MSG

#define ARM_COMPUTE_ERROR_ON_LOC_MSG (   cond,
  func,
  file,
  line,
  ... 
)

Definition at line 458 of file Error.h.

◆ ARM_COMPUTE_ERROR_ON_MSG

#define ARM_COMPUTE_ERROR_ON_MSG (   cond,
  msg 
)

Definition at line 456 of file Error.h.

◆ ARM_COMPUTE_ERROR_ON_MSG_VAR

#define ARM_COMPUTE_ERROR_ON_MSG_VAR (   cond,
  msg,
  ... 
)

Definition at line 457 of file Error.h.

◆ ARM_COMPUTE_ERROR_THROW_ON

#define ARM_COMPUTE_ERROR_THROW_ON (   status)

Definition at line 455 of file Error.h.

◆ ARM_COMPUTE_ERROR_VAR

#define ARM_COMPUTE_ERROR_VAR (   msg,
  ... 
)    ARM_COMPUTE_THROW_ERROR_VAR(__func__, __FILE__, __LINE__, msg, __VA_ARGS__)

Print the given message then throw an std::runtime_error.

Accepts a message format and a variable list of arguments matching the format description.

Parameters
[in]msgError description message format.
[in]...List of arguments matching the format description.

Definition at line 348 of file Error.h.

◆ ARM_COMPUTE_EXIT_ON_MSG

#define ARM_COMPUTE_EXIT_ON_MSG (   cond,
  msg 
)
Value:
do \
{ \
if (cond) \
{ \
ARM_COMPUTE_ERROR(msg); \
} \
} while (false)

If the condition is true, the given message is printed and program exits.

Parameters
[in]condCondition to evaluate.
[in]msgMessage to display.

Definition at line 382 of file Error.h.

◆ ARM_COMPUTE_EXIT_ON_MSG_VAR

#define ARM_COMPUTE_EXIT_ON_MSG_VAR (   cond,
  msg,
  ... 
)
Value:
do \
{ \
if (cond) \
{ \
ARM_COMPUTE_ERROR_VAR(msg, __VA_ARGS__); \
} \
} while (false)

If the condition is true, the given message is printed and program exits.

Accepts a message format and a variable list of arguments matching the format description.

Parameters
[in]condCondition to evaluate.
[in]msgError description message format.
[in]...List of arguments matching the format description.

Definition at line 398 of file Error.h.

◆ ARM_COMPUTE_RETURN_ERROR_MSG

#define ARM_COMPUTE_RETURN_ERROR_MSG (   ...)
Value:
do \
{ \
} while (false)

An error is returned with the given description.

Parameters
[in]...Error description message.

Definition at line 195 of file Error.h.

◆ ARM_COMPUTE_RETURN_ERROR_ON

#define ARM_COMPUTE_RETURN_ERROR_ON (   cond)    ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, #cond)

If the condition is true, an error is returned.

Parameters
[in]condCondition to evaluate

Definition at line 298 of file Error.h.

◆ ARM_COMPUTE_RETURN_ERROR_ON_LOC

#define ARM_COMPUTE_RETURN_ERROR_ON_LOC (   cond,
  func,
  file,
  line 
)    ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(cond, func, file, line, #cond)

If the condition is true, an error is returned.

Parameters
[in]condCondition to evaluate.
[in]funcFunction in which the error occurred.
[in]fileFile in which the error occurred.
[in]lineLine in which the error occurred.

Definition at line 307 of file Error.h.

◆ ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG

#define ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG (   cond,
  func,
  file,
  line,
  msg 
)
Value:
do \
{ \
if (cond) \
{ \
return arm_compute::create_error_msg(ErrorCode::RUNTIME_ERROR, func, file, line, msg); \
} \
} while (false)

If the condition is true, an error is thrown.

Parameters
[in]condCondition to evaluate.
[in]funcFunction in which the error occurred.
[in]fileFile in which the error occurred.
[in]lineLine in which the error occurred.
[in]msgMessage to display.

Definition at line 285 of file Error.h.

◆ ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG_VAR

#define ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG_VAR (   cond,
  func,
  file,
  line,
  msg,
  ... 
)
Value:
do \
{ \
if (cond) \
{ \
std::array<char, 512> out{0}; \
int offset = snprintf(out.data(), out.size(), "in %s %s:%d: ", func, file, line); \
snprintf(out.data() + offset, out.size() - offset, msg, __VA_ARGS__); \
return arm_compute::create_error(ErrorCode::RUNTIME_ERROR, std::string(out.data())); \
} \
} while (false)

If the condition is true, an error is thrown.

Accepts a message format and a variable list of arguments matching the format description.

Parameters
[in]condCondition to evaluate.
[in]funcFunction in which the error occurred.
[in]fileFile in which the error occurred.
[in]lineLine in which the error occurred.
[in]msgError description message format.
[in]...List of arguments matching the format description.

Definition at line 265 of file Error.h.

◆ ARM_COMPUTE_RETURN_ERROR_ON_MSG

#define ARM_COMPUTE_RETURN_ERROR_ON_MSG (   cond,
  msg 
)
Value:
do \
{ \
if (cond) \
{ \
msg); \
} \
} while (false)

If the condition is true, an error is returned.

Parameters
[in]condCondition to evaluate.
[in]msgError description message

Definition at line 245 of file Error.h.

◆ ARM_COMPUTE_RETURN_ERROR_ON_MSG_VAR

#define ARM_COMPUTE_RETURN_ERROR_ON_MSG_VAR (   cond,
  msg,
  ... 
)
Value:
do \
{ \
if (cond) \
{ \
std::array<char, 512> out{0}; \
int offset = snprintf(out.data(), out.size(), "in %s %s:%d: ", __func__, __FILE__, __LINE__); \
snprintf(out.data() + offset, out.size() - offset, msg, __VA_ARGS__); \
} \
} while (false)

If the condition is true, an error is returned.

Accepts a message format and a variable list of arguments matching the format description.

Parameters
[in]condCondition to evaluate.
[in]msgError description message format.
[in]...List of arguments matching the format description.

Definition at line 228 of file Error.h.

◆ ARM_COMPUTE_RETURN_ON_ERROR

#define ARM_COMPUTE_RETURN_ON_ERROR (   status)
Value:
do \
{ \
const auto s = status; \
if (!bool(s)) \
{ \
return s; \
} \
} while (false)

Checks if a status contains an error and returns it.

Parameters
[in]statusStatus value to check

Definition at line 205 of file Error.h.

◆ ARM_COMPUTE_THROW

#define ARM_COMPUTE_THROW (   ex)    throw(ex)

Definition at line 479 of file Error.h.

◆ ARM_COMPUTE_THROW_ERROR

#define ARM_COMPUTE_THROW_ERROR (   func,
  file,
  line,
  msg 
)
Value:

Print the given message then throw an std::runtime_error.

Parameters
[in]funcFunction in which the error occurred.
[in]fileFile in which the error occurred.
[in]lineLine in which the error occurred.
[in]msgMessage to display.

Definition at line 317 of file Error.h.

◆ ARM_COMPUTE_THROW_ERROR_VAR

#define ARM_COMPUTE_THROW_ERROR_VAR (   func,
  file,
  line,
  msg,
  ... 
)
Value:
do \
{ \
std::array<char, 512> out{0}; \
int offset = snprintf(out.data(), out.size(), "in %s %s:%d: ", func, file, line); \
snprintf(out.data() + offset, out.size() - offset, msg, __VA_ARGS__); \
} while (false)

Print the given message then throw an std::runtime_error.

Accepts a message format and a variable list of arguments matching the format description.

Parameters
[in]funcFunction in which the error occurred.
[in]fileFile in which the error occurred.
[in]lineLine in which the error occurred.
[in]msgError description message format.
[in]...List of arguments matching the format description.

Definition at line 333 of file Error.h.

◆ ARM_COMPUTE_THROW_ON_ERROR

#define ARM_COMPUTE_THROW_ON_ERROR (   error)    error.throw_if_error();

Checks if an error value is valid if not throws an exception with the error.

Parameters
[in]errorError value to check.

Definition at line 219 of file Error.h.

◆ ARM_COMPUTE_UNUSED

#define ARM_COMPUTE_UNUSED (   ...)    ::arm_compute::ignore_unused(__VA_ARGS__)

To avoid unused variables warnings.

This is useful if for example a variable is only used in debug builds and generates a warning in release builds.

Parameters
[in]...Variables which are unused.

Definition at line 151 of file Error.h.

arm_compute::create_error
Status create_error(ErrorCode error_code, std::string msg)
Creates an error containing the error message.
Definition: Error.cpp:34
arm_compute::create_error_msg
Status create_error_msg(ErrorCode error_code, const char *func, const char *file, int line, const char *msg)
Creates an error and the error message.
Definition: Error.cpp:40
arm_compute::support::cpp11::snprintf
int snprintf(char *s, std::size_t n, const char *fmt, Ts &&...args)
Loads the data from the given location, converts them to character string equivalents and writes the ...
Definition: ToolchainSupport.h:271
arm_compute::ErrorCode::RUNTIME_ERROR
@ RUNTIME_ERROR
Generic runtime error.
arm_compute::Status
Status class.
Definition: Error.h:52
offset
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Definition: helpers.h:1128
arm_compute::throw_error
void throw_error(Status err)
Throw an std::runtime_error.
Definition: Error.cpp:47
ARM_COMPUTE_CREATE_ERROR
#define ARM_COMPUTE_CREATE_ERROR(error_code, msg)
Creates an error with a given message.
Definition: Error.h:158