diff --git a/sycl/source/detail/device_impl.cpp b/sycl/source/detail/device_impl.cpp index d5762c4617bb9..af846c559cfea 100644 --- a/sycl/source/detail/device_impl.cpp +++ b/sycl/source/detail/device_impl.cpp @@ -76,10 +76,14 @@ device_impl::device_impl(ur_native_handle_t InteropDeviceHandle, } device_impl::~device_impl() { - // TODO catch an exception and put it to list of asynchronous exceptions - const PluginPtr &Plugin = getPlugin(); - ur_result_t Err = Plugin->call_nocheck(urDeviceRelease, MDevice); - __SYCL_CHECK_OCL_CODE_NO_EXC(Err); + try { + // TODO catch an exception and put it to list of asynchronous exceptions + const PluginPtr &Plugin = getPlugin(); + ur_result_t Err = Plugin->call_nocheck(urDeviceRelease, MDevice); + __SYCL_CHECK_OCL_CODE_NO_EXC(Err); + } catch (std::exception &e) { + __SYCL_REPORT_EXCEPTION_TO_STREAM("exception in ~device_impl", e); + } } bool device_impl::is_affinity_supported( diff --git a/sycl/source/detail/kernel_program_cache.hpp b/sycl/source/detail/kernel_program_cache.hpp index aeb847483b9ee..5cc626b449aaa 100644 --- a/sycl/source/detail/kernel_program_cache.hpp +++ b/sycl/source/detail/kernel_program_cache.hpp @@ -100,9 +100,14 @@ class KernelProgramCache { this->State.store(InitialState); } ~ProgramBuildResult() { - if (Val) { - ur_result_t Err = Plugin->call_nocheck(urProgramRelease, Val); - __SYCL_CHECK_OCL_CODE_NO_EXC(Err); + try { + if (Val) { + ur_result_t Err = Plugin->call_nocheck(urProgramRelease, Val); + __SYCL_CHECK_OCL_CODE_NO_EXC(Err); + } + } catch (std::exception &e) { + __SYCL_REPORT_EXCEPTION_TO_STREAM("exception in ~ProgramBuildResult", + e); } } }; @@ -133,9 +138,13 @@ class KernelProgramCache { Val.first = nullptr; } ~KernelBuildResult() { - if (Val.first) { - ur_result_t Err = Plugin->call_nocheck(urKernelRelease, Val.first); - __SYCL_CHECK_OCL_CODE_NO_EXC(Err); + try { + if (Val.first) { + ur_result_t Err = Plugin->call_nocheck(urKernelRelease, Val.first); + __SYCL_CHECK_OCL_CODE_NO_EXC(Err); + } + } catch (std::exception &e) { + __SYCL_REPORT_EXCEPTION_TO_STREAM("exception in ~KernelBuildResult", e); } } };