From dacde41924601ea11afeabf93cba63fe23a41b75 Mon Sep 17 00:00:00 2001 From: Tianyu Liu Date: Tue, 21 Jan 2025 15:41:03 -0500 Subject: [PATCH] Improve noexcept guarantee --- cpp/src/file_handle.cpp | 21 ++++++++++++--------- cpp/src/shim/cufile.cpp | 4 ++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/cpp/src/file_handle.cpp b/cpp/src/file_handle.cpp index c871495640..9c025c8d45 100644 --- a/cpp/src/file_handle.cpp +++ b/cpp/src/file_handle.cpp @@ -190,15 +190,18 @@ bool FileHandle::closed() const noexcept { return !_initialized; } void FileHandle::close() noexcept { - if (closed()) { return; } - - if (!is_compat_mode_preferred()) { cuFileAPI::instance().HandleDeregister(_handle); } - _compat_mode = CompatMode::AUTO; - ::close(_fd_direct_off); - if (_fd_direct_on != -1) { ::close(_fd_direct_on); } - _fd_direct_on = -1; - _fd_direct_off = -1; - _initialized = false; + try { + if (closed()) { return; } + + if (!is_compat_mode_preferred()) { cuFileAPI::instance().HandleDeregister(_handle); } + _compat_mode = CompatMode::AUTO; + ::close(_fd_direct_off); + if (_fd_direct_on != -1) { ::close(_fd_direct_on); } + _fd_direct_on = -1; + _fd_direct_off = -1; + _initialized = false; + } catch (...) { + } } CUfileHandle_t FileHandle::handle() diff --git a/cpp/src/shim/cufile.cpp b/cpp/src/shim/cufile.cpp index b139b50b06..ce252873c8 100644 --- a/cpp/src/shim/cufile.cpp +++ b/cpp/src/shim/cufile.cpp @@ -127,7 +127,7 @@ bool is_cufile_library_available() noexcept { try { cuFileAPI::instance(); - } catch (const std::runtime_error&) { + } catch (...) { return false; } return true; @@ -144,7 +144,7 @@ int cufile_version() noexcept { try { return cuFileAPI::instance().version; - } catch (std::runtime_error const&) { + } catch (...) { return 0; } }