24.02
|
Go to the documentation of this file.
24 #ifndef ARM_COMPUTE_ERROR_H
25 #define ARM_COMPUTE_ERROR_H
38 template <
typename... T>
80 explicit operator bool() const noexcept
98 return _error_description;
105 internal_throw_on_error();
111 [[noreturn]]
void internal_throw_on_error()
const;
115 std::string _error_description;
151 #define ARM_COMPUTE_UNUSED(...) ::arm_compute::ignore_unused(__VA_ARGS__) // NOLINT
158 #define ARM_COMPUTE_CREATE_ERROR(error_code, msg) \
159 arm_compute::create_error_msg(error_code, __func__, __FILE__, __LINE__, msg)
169 #define ARM_COMPUTE_CREATE_ERROR_LOC(error_code, func, file, line, msg) \
170 arm_compute::create_error_msg(error_code, func, file, line, msg)
182 #define ARM_COMPUTE_CREATE_ERROR_LOC_VAR(error_code, func, file, line, msg, ...) \
185 std::array<char, 512> out{0}; \
186 int offset = snprintf(out.data(), out.size(), "in %s %s:%d: ", func, file, line); \
187 snprintf(out.data() + offset, out.size() - offset, msg, __VA_ARGS__); \
188 arm_compute::create_error(error_code, std::string(out.data())); \
195 #define ARM_COMPUTE_RETURN_ERROR_MSG(...) \
198 return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, __VA_ARGS__); \
205 #define ARM_COMPUTE_RETURN_ON_ERROR(status) \
208 const auto s = status; \
219 #define ARM_COMPUTE_THROW_ON_ERROR(error) error.throw_if_error();
228 #define ARM_COMPUTE_RETURN_ERROR_ON_MSG_VAR(cond, msg, ...) \
233 std::array<char, 512> out{0}; \
234 int offset = snprintf(out.data(), out.size(), "in %s %s:%d: ", __func__, __FILE__, __LINE__); \
235 snprintf(out.data() + offset, out.size() - offset, msg, __VA_ARGS__); \
236 return arm_compute::create_error(arm_compute::ErrorCode::RUNTIME_ERROR, std::string(out.data())); \
245 #define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg) \
250 return arm_compute::create_error_msg(arm_compute::ErrorCode::RUNTIME_ERROR, __func__, __FILE__, __LINE__, \
265 #define ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG_VAR(cond, func, file, line, msg, ...) \
270 std::array<char, 512> out{0}; \
271 int offset = snprintf(out.data(), out.size(), "in %s %s:%d: ", func, file, line); \
272 snprintf(out.data() + offset, out.size() - offset, msg, __VA_ARGS__); \
273 return arm_compute::create_error(ErrorCode::RUNTIME_ERROR, std::string(out.data())); \
285 #define ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(cond, func, file, line, msg) \
290 return arm_compute::create_error_msg(ErrorCode::RUNTIME_ERROR, func, file, line, msg); \
298 #define ARM_COMPUTE_RETURN_ERROR_ON(cond) ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, #cond)
307 #define ARM_COMPUTE_RETURN_ERROR_ON_LOC(cond, func, file, line) \
308 ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(cond, func, file, line, #cond)
317 #define ARM_COMPUTE_THROW_ERROR(func, file, line, msg) \
320 arm_compute::throw_error( \
321 arm_compute::create_error_msg(arm_compute::ErrorCode::RUNTIME_ERROR, func, file, line, msg)); \
333 #define ARM_COMPUTE_THROW_ERROR_VAR(func, file, line, msg, ...) \
336 std::array<char, 512> out{0}; \
337 int offset = snprintf(out.data(), out.size(), "in %s %s:%d: ", func, file, line); \
338 snprintf(out.data() + offset, out.size() - offset, msg, __VA_ARGS__); \
339 arm_compute::throw_error(arm_compute::Status(arm_compute::ErrorCode::RUNTIME_ERROR, std::string(out.data()))); \
348 #define ARM_COMPUTE_ERROR_VAR(msg, ...) ARM_COMPUTE_THROW_ERROR_VAR(__func__, __FILE__, __LINE__, msg, __VA_ARGS__)
354 #define ARM_COMPUTE_ERROR(msg) ARM_COMPUTE_THROW_ERROR(__func__, __FILE__, __LINE__, msg)
365 #define ARM_COMPUTE_ERROR_LOC_VAR(func, file, line, msg, ...) \
366 ARM_COMPUTE_THROW_ERROR_VAR(func, file, line, msg, __VA_ARGS__) // NOLINT
375 #define ARM_COMPUTE_ERROR_LOC(func, file, line, msg) ARM_COMPUTE_THROW_ERROR(func, file, line, msg) // NOLINT
382 #define ARM_COMPUTE_EXIT_ON_MSG(cond, msg) \
387 ARM_COMPUTE_ERROR(msg); \
398 #define ARM_COMPUTE_EXIT_ON_MSG_VAR(cond, msg, ...) \
403 ARM_COMPUTE_ERROR_VAR(msg, __VA_ARGS__); \
407 #ifdef ARM_COMPUTE_ASSERTS_ENABLED
412 #define ARM_COMPUTE_ERROR_THROW_ON(status) status.throw_if_error()
419 #define ARM_COMPUTE_ERROR_ON_MSG(cond, msg) ARM_COMPUTE_EXIT_ON_MSG(cond, msg)
428 #define ARM_COMPUTE_ERROR_ON_MSG_VAR(cond, msg, ...) 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) ARM_COMPUTE_ERROR_ON_MSG(cond, #cond)
475 #define ARM_COMPUTE_ERROR_ON_LOC(cond, func, file, line) \
476 ARM_COMPUTE_ERROR_ON_LOC_MSG(cond, func, file, line, "%s", #cond)
478 #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
479 #define ARM_COMPUTE_THROW(ex) throw(ex)
481 #define ARM_COMPUTE_THROW(ex) (ex), std::abort()
Status create_error(ErrorCode error_code, std::string msg)
Creates an error containing the error message.
Status(ErrorCode error_status, std::string error_description=" ")
Default Constructor.
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.
std::string error_description() const
Gets error description if any.
@ RUNTIME_ERROR
Generic runtime error.
ErrorCode
Available error codes.
void throw_if_error() const
Throws a runtime exception in case it contains a valid error status.
void throw_error(Status err)
Throw an std::runtime_error.
Status & operator=(const Status &)=default
Allow instances of this class to be copy assigned.
ErrorCode error_code() const
Gets error code.
void ignore_unused(T &&...)
Ignores unused arguments.
Copyright (c) 2017-2024 Arm Limited.
Status()
Default Constructor.
@ UNSUPPORTED_EXTENSION_USE
Unsupported extension used.