31#ifndef DW_FRAMEWORK_EXCEPTION_HPP_
32#define DW_FRAMEWORK_EXCEPTION_HPP_
34#include <dw/core/base/Exception.hpp>
35#include <dw/core/base/Status.h>
36#include <dw/core/container/BaseString.hpp>
37#include <dw/core/logger/Logger.hpp>
39#define THROW_ON_PARAM_NULL(param) \
40 if (param == nullptr) \
42 throw dw::core::ExceptionWithStatus(DW_INVALID_ARGUMENT, #param " == nullptr ", DW_FUNCTION_NAME, ":", __LINE__); \
47#define FRWK_CHECK_DW_ERROR(x) \
51 if (result != DW_SUCCESS) \
53 throw dw::core::ExceptionWithStatus(result, __FILE__, ":", __LINE__, " - DriveWorks Error"); \
56#define GET_STRING(s) #s
57#define FRWK_CHECK_DW_ERROR_IGNORE_SOME(x, fallback, ...) \
59 dwStatus result = x; \
60 dwStatus ignoreErros[] = {__VA_ARGS__}; \
61 if (result != DW_SUCCESS) \
63 if (std::find(std::begin(ignoreErros), std::end(ignoreErros), result) != std::end(ignoreErros)) \
66 << "(" << __LINE__ << ") " \
67 << "Ignoring Error: " \
68 << dwGetStatusName(result) << ". Falling back on calling " << GET_STRING(fallback) \
69 << dw::core::Logger::State::endl; \
71 if (result != DW_SUCCESS) \
73 throw dw::core::ExceptionWithStatus(result, "After ignoring errors from ignore list, fallback operation %s encountered DriveWorks error.", GET_STRING(fallback)); \
77 if (result != DW_SUCCESS) \
79 throw dw::core::ExceptionWithStatus(result, "DriveWorks error not in ignore list."); \
83#define FRWK_CHECK_DW_ERROR_NOTHROW(x) \
85 dwStatus result = x; \
86 if (result != DW_SUCCESS) \
89 << "(" << __LINE__ << ") " \
90 << "DriveWorks exception but not thrown: " \
91 << dwGetStatusName(result) \
92 << dw::core::Logger::State::endl; \
96#define FRWK_CHECK_DW_ERROR_NOTHROW_IGNORE_SOME(x, fallback, ...) \
98 dwStatus result = x; \
99 dwStatus ignoreErros[] = {__VA_ARGS__}; \
100 if (std::find(std::begin(ignoreErros), std::end(ignoreErros), result) != std::end(ignoreErros)) \
104 if (result != DW_SUCCESS) \
106 DW_LOGE << __FILE__ \
107 << "(" << __LINE__ << ") " \
108 << "DriveWorks exception but not thrown: " \
109 << dwGetStatusName(result) \
110 << dw::core::Logger::State::endl; \
114#define FRWK_CHECK_DW_ERROR_MSG(x, description) \
118 if (result != DW_SUCCESS) \
120 throw dw::core::ExceptionWithStatus(result, (description)); \
126#define FRWK_CHECK_CUDA_ERROR(x) \
129 auto result = cudaGetLastError(); \
130 if (result != cudaSuccess) \
132 throw dw::core::ExceptionWithStatus(DW_CUDA_ERROR, cudaGetErrorString(result)); \
136#define FRWK_CHECK_CUDA_ERROR_NOTHROW(x) \
139 auto result = cudaGetLastError(); \
140 if (result != cudaSuccess) \
142 DW_LOGE << __FILE__ \
143 << "(" << __LINE__ << ") " \
144 << "CUDA error but not thrown: " \
145 << cudaGetErrorString(result) \
146 << dw::core::Logger::State::endl; \
150#define FRWK_CHECK_NVMEDIA_ERROR(e) \
152 auto FRWK_CHECK_NVMEDIA_ERROR_ret = (e); \
153 if (FRWK_CHECK_NVMEDIA_ERROR_ret != NVMEDIA_STATUS_OK) \
155 throw dw::core::ExceptionWithStatus(DW_NVMEDIA_ERROR, "NvMedia error occured"); \