24 #ifndef __ARM_COMPUTE_ERROR_H__ 25 #define __ARM_COMPUTE_ERROR_H__ 38 template <
typename... T>
81 explicit operator bool() const noexcept
99 return _error_description;
106 internal_throw_on_error();
112 [[noreturn]]
void internal_throw_on_error()
const;
116 std::string _error_description;
152 #define ARM_COMPUTE_UNUSED(...) ::arm_compute::ignore_unused(__VA_ARGS__) // NOLINT 159 #define ARM_COMPUTE_CREATE_ERROR(error_code, msg) arm_compute::create_error_msg(error_code, __func__, __FILE__, __LINE__, msg) 169 #define ARM_COMPUTE_CREATE_ERROR_LOC(error_code, func, file, line, msg) arm_compute::create_error_msg(error_code, func, file, line, msg) 181 #define ARM_COMPUTE_CREATE_ERROR_LOC_VAR(error_code, func, file, line, msg, ...) \ 184 std::array<char, 512> out{ 0 }; \ 185 int offset = snprintf(out.data(), out.size(), "in %s %s:%d: ", func, file, line); \ 186 snprintf(out.data() + offset, out.size() - offset, msg, __VA_ARGS__); \ 187 arm_compute::create_error(error_code, std::string(out.data())); \ 194 #define ARM_COMPUTE_RETURN_ERROR_MSG(...) \ 197 return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, __VA_ARGS__); \ 204 #define ARM_COMPUTE_RETURN_ON_ERROR(status) \ 217 #define ARM_COMPUTE_THROW_ON_ERROR(error) \ 218 error.throw_if_error(); 227 #define ARM_COMPUTE_RETURN_ERROR_ON_MSG_VAR(cond, msg, ...) \ 232 std::array<char, 512> out{ 0 }; \ 233 int offset = snprintf(out.data(), out.size(), "in %s %s:%d: ", __func__, __FILE__, __LINE__); \ 234 snprintf(out.data() + offset, out.size() - offset, msg, __VA_ARGS__); \ 235 return arm_compute::create_error(arm_compute::ErrorCode::RUNTIME_ERROR, std::string(out.data())); \ 244 #define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg) \ 249 return arm_compute::create_error_msg(arm_compute::ErrorCode::RUNTIME_ERROR, __func__, __FILE__, __LINE__, msg); \ 263 #define ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG_VAR(cond, func, file, line, msg, ...) \ 268 std::array<char, 512> out{ 0 }; \ 269 int offset = snprintf(out.data(), out.size(), "in %s %s:%d: ", func, file, line); \ 270 snprintf(out.data() + offset, out.size() - offset, msg, __VA_ARGS__); \ 271 return arm_compute::create_error(ErrorCode::RUNTIME_ERROR, std::string(out.data())); \ 283 #define ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(cond, func, file, line, msg) \ 288 return arm_compute::create_error_msg(ErrorCode::RUNTIME_ERROR, func, file, line, msg); \ 296 #define ARM_COMPUTE_RETURN_ERROR_ON(cond) \ 297 ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, #cond) 306 #define ARM_COMPUTE_RETURN_ERROR_ON_LOC(cond, func, file, line) \ 307 ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(cond, func, file, line, #cond) 316 #define ARM_COMPUTE_THROW_ERROR(func, file, line, msg) \ 319 arm_compute::throw_error(arm_compute::create_error_msg(arm_compute::ErrorCode::RUNTIME_ERROR, func, file, line, msg)); \ 331 #define ARM_COMPUTE_THROW_ERROR_VAR(func, file, line, msg, ...) \ 334 std::array<char, 512> out{ 0 }; \ 335 int offset = snprintf(out.data(), out.size(), "in %s %s:%d: ", func, file, line); \ 336 snprintf(out.data() + offset, out.size() - offset, msg, __VA_ARGS__); \ 337 arm_compute::throw_error(arm_compute::Status(arm_compute::ErrorCode::RUNTIME_ERROR, std::string(out.data()))); \ 346 #define ARM_COMPUTE_ERROR_VAR(msg, ...) ARM_COMPUTE_THROW_ERROR_VAR(__func__, __FILE__, __LINE__, msg, __VA_ARGS__) 352 #define ARM_COMPUTE_ERROR(msg) ARM_COMPUTE_THROW_ERROR(__func__, __FILE__, __LINE__, msg) 363 #define ARM_COMPUTE_ERROR_LOC_VAR(func, file, line, msg, ...) ARM_COMPUTE_THROW_ERROR_VAR(func, file, line, msg, __VA_ARGS__) // NOLINT 372 #define ARM_COMPUTE_ERROR_LOC(func, file, line, msg) ARM_COMPUTE_THROW_ERROR(func, file, line, msg) // NOLINT 379 #define ARM_COMPUTE_EXIT_ON_MSG(cond, msg) \ 384 ARM_COMPUTE_ERROR(msg); \ 395 #define ARM_COMPUTE_EXIT_ON_MSG_VAR(cond, msg, ...) \ 400 ARM_COMPUTE_ERROR_VAR(msg, __VA_ARGS__); \ 404 #ifdef ARM_COMPUTE_ASSERTS_ENABLED 409 #define ARM_COMPUTE_ERROR_THROW_ON(status) \ 410 status.throw_if_error() 417 #define ARM_COMPUTE_ERROR_ON_MSG(cond, msg) \ 418 ARM_COMPUTE_EXIT_ON_MSG(cond, msg) 427 #define ARM_COMPUTE_ERROR_ON_MSG_VAR(cond, msg, ...) \ 428 ARM_COMPUTE_EXIT_ON_MSG_VAR(cond, msg, __VA_ARGS__) 438 #define ARM_COMPUTE_ERROR_ON_LOC_MSG(cond, func, file, line, ...) \ 443 ARM_COMPUTE_ERROR_LOC_VAR(func, file, line, __VA_ARGS__); \ 453 #define ARM_COMPUTE_CONST_ON_ERROR(cond, val, msg) (cond) ? throw std::logic_error(msg) : val; 455 #define ARM_COMPUTE_ERROR_THROW_ON(status) 456 #define ARM_COMPUTE_ERROR_ON_MSG(cond, msg) 457 #define ARM_COMPUTE_ERROR_ON_MSG_VAR(cond, msg, ...) 458 #define ARM_COMPUTE_ERROR_ON_LOC_MSG(cond, func, file, line, ...) 459 #define ARM_COMPUTE_CONST_ON_ERROR(cond, val, msg) val 466 #define ARM_COMPUTE_ERROR_ON(cond) \ 467 ARM_COMPUTE_ERROR_ON_MSG(cond, #cond) 476 #define ARM_COMPUTE_ERROR_ON_LOC(cond, func, file, line) \ 477 ARM_COMPUTE_ERROR_ON_LOC_MSG(cond, func, file, line, "%s", #cond) 479 #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED 480 #define ARM_COMPUTE_THROW(ex) throw(ex) 482 #define ARM_COMPUTE_THROW(ex) (ex), std::abort() 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.
Unsupported extension used.
Status(ErrorCode error_status, std::string error_description=" ")
Default Constructor.
Copyright (c) 2017-2019 ARM Limited.
void throw_error(Status err)
Throw an std::runtime_error.
ErrorCode
Available error codes.
Status & operator=(const Status &)=default
Allow instances of this class to be copy assigned.
void ignore_unused(T &&...)
Ignores unused arguments.
void throw_if_error() const
Throws a runtime exception in case it contains a valid error status.
Status create_error(ErrorCode error_code, std::string msg)
Creates an error containing the error message.
Status()
Default Constructor.
std::string error_description() const
Gets error description if any.
ErrorCode error_code() const
Gets error code.