diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2024-07-02 16:34:52 +0500 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2024-07-02 20:18:04 +0200 |
commit | 6144341c8ee50c5623d9352c5dbb43785a728bca (patch) | |
tree | 8fceb7c45d2bd2e5b14afba33d3bc72d6609443e /include | |
parent | 3b824baa863880ada2a8e8178c35d56c1aafab8f (diff) |
Add source location to ComError
And use in CSysShExec::execute to improve location reporting
Change-Id: I624df0418b99a79207f5aeefa38d2bfe5ea7ffe1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169880
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'include')
-rw-r--r-- | include/systools/win32/comtools.hxx | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/include/systools/win32/comtools.hxx b/include/systools/win32/comtools.hxx index 124759189c15..9c2f49e8be0a 100644 --- a/include/systools/win32/comtools.hxx +++ b/include/systools/win32/comtools.hxx @@ -19,6 +19,9 @@ #pragma once +#include <sal/config.h> + +#include <source_location> #include <string> #include <string_view> #include <stdexcept> @@ -35,22 +38,27 @@ namespace sal::systools class ComError : public std::runtime_error { public: - ComError(const std::string& message, HRESULT hr) : - std::runtime_error(message), - hr_(hr) + ComError(std::string_view message, HRESULT hr, + const std::source_location& loc = std::source_location::current()) + : std::runtime_error(std::string(message)) + , hr_(hr) + , loc_(loc) {} HRESULT GetHresult() const { return hr_; } + const std::source_location& GetLocation() const { return loc_; } private: HRESULT hr_; + std::source_location loc_; }; /* Convert failed HRESULT to thrown ComError */ - inline void ThrowIfFailed(HRESULT hr, std::string_view msg) + inline void ThrowIfFailed(HRESULT hr, std::string_view msg, + std::source_location loc = std::source_location::current()) { if (FAILED(hr)) - throw ComError(std::string(msg), hr); + throw ComError(msg, hr, loc); } /* A guard class to call CoInitializeEx/CoUninitialize in proper pairs |