31#ifndef DW_FRAMEWORK_EXCEPTION_HPP_
32#define DW_FRAMEWORK_EXCEPTION_HPP_
34#include <dwshared/dwfoundation/dw/core/base/ExceptionWithStatus.hpp>
35#include <dw/core/base/Status.h>
36#include <dwshared/dwfoundation/dw/core/container/BaseString.hpp>
37#include <dwshared/dwfoundation/dw/core/language/Function.hpp>
38#include <dwshared/dwfoundation/dw/core/logger/Logger.hpp>
40#define THROW_ON_PARAM_NULL(param) \
41 if (param == nullptr) \
43 throw dw::core::ExceptionWithStatus(DW_INVALID_ARGUMENT, #param " == nullptr ", DW_FUNCTION_NAME, ":", __LINE__); \
48#define FRWK_CHECK_DW_ERROR(x) \
52 if (result != DW_SUCCESS) \
54 throw dw::core::ExceptionWithStatus(result, __FILE__, ":", __LINE__, " - DriveWorks Error"); \
57#define GET_STRING(s) #s
58#define FRWK_CHECK_DW_ERROR_IGNORE_SOME(x, fallback, ...) \
60 dwStatus result = x; \
61 dwStatus ignoreErros[] = {__VA_ARGS__}; \
62 if (result != DW_SUCCESS) \
64 if (std::find(std::begin(ignoreErros), std::end(ignoreErros), result) != std::end(ignoreErros)) \
67 << "(" << __LINE__ << ") " \
68 << "Ignoring Error: " \
69 << dwGetStatusName(result) << ". Falling back on calling " << GET_STRING(fallback) \
70 << dw::core::Logger::State::endl; \
72 if (result != DW_SUCCESS) \
74 throw dw::core::ExceptionWithStatus(result, "After ignoring errors from ignore list, fallback operation %s encountered DriveWorks error.", GET_STRING(fallback)); \
78 if (result != DW_SUCCESS) \
80 throw dw::core::ExceptionWithStatus(result, "DriveWorks error not in ignore list."); \
84#define FRWK_CHECK_DW_ERROR_NOTHROW(x) \
87 if (result != DW_SUCCESS) \
90 << "(" << __LINE__ << ") " \
91 << "DriveWorks exception but not thrown: " \
92 << dwGetStatusName(result) \
93 << dw::core::Logger::State::endl; \
97#define FRWK_CHECK_DW_ERROR_NOTHROW_IGNORE_SOME(x, fallback, ...) \
99 dwStatus result = x; \
100 dwStatus ignoreErros[] = {__VA_ARGS__}; \
101 if (std::find(std::begin(ignoreErros), std::end(ignoreErros), result) != std::end(ignoreErros)) \
105 if (result != DW_SUCCESS) \
107 DW_LOGE << __FILE__ \
108 << "(" << __LINE__ << ") " \
109 << "DriveWorks exception but not thrown: " \
110 << dwGetStatusName(result) \
111 << dw::core::Logger::State::endl; \
115#define FRWK_CHECK_DW_ERROR_MSG(x, description) \
117 dwStatus result{x}; \
118 if (result != DW_SUCCESS) \
120 throw dw::core::ExceptionWithStatus(result, (description)); \
126#define FRWK_CHECK_CUDA_ERROR(x) \
129 cudaError_t 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 cudaError_t 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 NvMediaStatus 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"); \
170 template <
typename TryBlock>
171 static dwStatus
guardWithReturn(TryBlock
const& tryBlock, ::dw::core::Logger::Verbosity verbosity = ::dw::core::Logger::Verbosity::ERROR)
173 return guardWithReturnFunction(tryBlock, verbosity);
176 template <
typename TryBlock>
177 static dwStatus
guard(TryBlock
const& tryBlock, ::dw::core::Logger::Verbosity verbosity = ::dw::core::Logger::Verbosity::ERROR)
179 static_assert(std::is_same<void,
typename std::result_of<TryBlock()>::type>::value,
180 "tryBlock must return void");
181 dw::core::Function<dwStatus()> tryBlockFunc{[&]() -> dwStatus {
185 return guardWithReturnFunction(tryBlockFunc, verbosity);
189 static dwStatus guardWithReturnFunction(dw::core::Function<dwStatus()>
const& tryBlock, dw::core::Logger::Verbosity verbosity);
static dwStatus guardWithReturn(TryBlock const &tryBlock, ::dw::core::Logger::Verbosity verbosity=::dw::core::Logger::Verbosity::ERROR)
static dwStatus guard(TryBlock const &tryBlock, ::dw::core::Logger::Verbosity verbosity=::dw::core::Logger::Verbosity::ERROR)