31 #ifndef DW_FRAMEWORK_EXCEPTION_HPP_ 32 #define DW_FRAMEWORK_EXCEPTION_HPP_ 35 #include <dw/core/base/ExceptionWithStackTrace.hpp> 36 #include <dw/core/base/Status.h> 37 #include <dw/core/container/BaseString.hpp> 38 #include <nvscierror.h> 40 #define THROW_ON_PARAM_NULL(param) \ 41 if (param == nullptr) \ 43 throw dw::framework::Exception(DW_INVALID_ARGUMENT, #param " == nullptr ", DW_FUNCTION_NAME, ":", __LINE__); \ 56 static constexpr char8_t
LOG_TAG[] =
"Exception";
59 :
dw::core::ExceptionBase(dwGetStatusName(statusCode))
60 , m_statusCode(statusCode)
64 m_messageBegin = m_what.length();
72 template <
class... Tothers>
76 (void)std::initializer_list<int32_t>{(
static_cast<void>(m_what << others), 0)...};
86 return what() + m_messageBegin;
101 template <
typename TryBlock>
108 template <
typename TryBlock>
109 static dwStatus
guard(TryBlock tryBlock);
111 template <
typename TryBlock>
115 dwStatus m_statusCode;
116 size_t m_messageBegin;
121 template <
typename TryBlock>
124 using FixedString = dw::core::BaseString<40>;
127 auto const logException = [](
const dwStatus
status,
const auto& ex, FixedString errorMessage) -> dwStatus {
131 DW_LOGD << errorMessage
132 << dwGetStatusName(status)
135 << Logger::State::endl
137 << Logger::State::endl;
151 DW_LOGD <<
"Framework exception thrown: " 152 << dwGetStatusName(ex.
status())
155 << Logger::State::endl;
158 catch (
const BufferFullException& ex)
163 return logException(DW_BUFFER_FULL, ex, FixedString(
"Framework exception thrown: "));
165 catch (
const BufferEmptyException& ex)
169 return logException(DW_NOT_AVAILABLE, ex, FixedString(
"Framework exception thrown: "));
171 catch (
const OutOfBoundsException& ex)
175 return logException(DW_OUT_OF_BOUNDS, ex, FixedString(
"Framework exception thrown: "));
177 catch (
const InvalidArgumentException& ex)
181 return logException(DW_INVALID_ARGUMENT, ex, FixedString(
"Framework exception thrown: "));
183 catch (
const BadAlignmentException& ex)
187 return logException(DW_BAD_ALIGNMENT, ex, FixedString(
"Framework exception thrown: "));
189 catch (
const CudaException& ex)
193 return logException(DW_CUDA_ERROR, ex, FixedString(
"Framework exception thrown: "));
195 catch (
const ExceptionWithStackTrace& ex)
199 return logException(DW_FAILURE, ex, FixedString(
"Framework exception thrown: "));
201 catch (
const std::exception& ex)
206 DW_LOGD <<
"std::exception thrown: " 207 << dwGetStatusName(DW_FAILURE)
210 << Logger::State::endl;
218 DW_LOGD <<
"Unknown exception thrown, " 219 << dwGetStatusName(DW_FAILURE)
220 << Logger::State::endl;
227 template <
typename TryBlock>
230 static_assert(std::is_same<
void,
typename std::result_of<TryBlock()>::type>::value,
231 "tryBlock must return void");
240 template <
typename TryBlock>
262 #define FRWK_CHECK_DW_ERROR(x) \ 264 dwStatus result = x; \ 265 if (result != DW_SUCCESS) \ 267 throw dw::framework::Exception(result, "DriveWorks Error"); \ 270 #define GET_STRING(s) #s 271 #define FRWK_CHECK_DW_ERROR_IGNORE_SOME(x, fallback, ...) \ 273 dwStatus result = x; \ 274 dwStatus ignoreErros[] = {__VA_ARGS__}; \ 275 if (result != DW_SUCCESS) \ 277 if (std::find(std::begin(ignoreErros), std::end(ignoreErros), result) != std::end(ignoreErros)) \ 279 DW_LOGD << __FILE__ \ 280 << "(" << __LINE__ << ") " \ 281 << "Ignoring Error: " \ 282 << dwGetStatusName(result) << ". Falling back on calling " << GET_STRING(fallback) \ 283 << dw::core::Logger::State::endl; \ 285 if (result != DW_SUCCESS) \ 287 throw dw::framework::Exception(result, "After ignoring errors from ignore list, fallback operation %s encountered DriveWorks error.", GET_STRING(fallback)); \ 291 if (result != DW_SUCCESS) \ 293 throw dw::framework::Exception(result, "DriveWorks error not in ignore list."); \ 297 #define FRWK_CHECK_DW_ERROR_NOTHROW(x) \ 299 dwStatus result = x; \ 300 if (result != DW_SUCCESS) \ 302 DW_LOGE << __FILE__ \ 303 << "(" << __LINE__ << ") " \ 304 << "DriveWorks exception but not thrown: " \ 305 << dwGetStatusName(result) \ 306 << dw::core::Logger::State::endl; \ 310 #define FRWK_CHECK_DW_ERROR_MSG(x, description) \ 312 dwStatus result = (x); \ 313 if (result != DW_SUCCESS) \ 315 throw dw::framework::Exception(result, (description)); \ 321 #define FRWK_CHECK_CUDA_ERROR(x) \ 324 auto result = cudaGetLastError(); \ 325 if (result != cudaSuccess) \ 327 throw dw::framework::Exception(DW_CUDA_ERROR, cudaGetErrorString(result)); \ 331 #define FRWK_CHECK_CUDA_ERROR_NOTHROW(x) \ 334 auto result = cudaGetLastError(); \ 335 if (result != cudaSuccess) \ 337 DW_LOGE << __FILE__ \ 338 << "(" << __LINE__ << ") " \ 339 << "CUDA error but not thrown: " \ 340 << cudaGetErrorString(result) \ 341 << dw::core::Logger::State::endl; \ 345 #define FRWK_CHECK_NVMEDIA_ERROR(e) \ 347 auto FRWK_CHECK_NVMEDIA_ERROR_ret = (e); \ 348 if (FRWK_CHECK_NVMEDIA_ERROR_ret != NVMEDIA_STATUS_OK) \ 350 throw dw::framework::Exception(DW_NVMEDIA_ERROR, "NvMedia error occured"); \ 354 #define FRWK_CHECK_NVSCI_ERROR(e) \ 356 auto FRWK_CHECK_NVSCI_ERROR_ret = (e); \ 357 if (FRWK_CHECK_NVSCI_ERROR_ret != NvSciError_Success) \ 359 DW_LOGE << "Failed with " << nvSciGetErrorName(FRWK_CHECK_NVSCI_ERROR_ret) \ 360 << "(" << FRWK_CHECK_NVSCI_ERROR_ret << ")" \ 361 << " in " << __FILE__ \ 362 << ":" << __LINE__ << Logger::State::endl; \ 363 if (FRWK_CHECK_NVSCI_ERROR_ret == NvSciError_Timeout) \ 364 throw Exception(DW_TIME_OUT, "NvSci API Timeout"); \ 366 throw Exception(DW_INTERNAL_ERROR, "NvSci internal error occured"); \ 370 #endif // DW_FRAMEWORK_TYPES_HPP_ static dwStatus guardWithNoPrint(TryBlock tryBlock)
static dwStatus guardWithReturn(TryBlock tryBlock)
Simple try/catch handler to catch dw::core::Exception and return a dwStatus error code if the given f...
Exception(dwStatus statusCode, const char8_t *messageStr)
char8_t const * messageStr() const noexcept
Exception(dwStatus statusCode, const char8_t *messageStr, Tothers... others)
static dwStatus guard(TryBlock tryBlock)
Same as previous guard but with a simpler tryBlock with signature 'void tryBlock()' Always returns DW...
const char * nvSciGetEventName(uint32_t event)
static constexpr char8_t LOG_TAG[]
const char * nvSciGetErrorName(uint32_t error)
~Exception() noexcept override=default