summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2024-07-02 14:47:57 +0500
committerMike Kaganski <mike.kaganski@collabora.com>2024-07-02 20:17:54 +0200
commit3b824baa863880ada2a8e8178c35d56c1aafab8f (patch)
tree8dc85dacf9a19162f4dd75dbfaa6c197e6e646e2 /shell
parent2467e7c874aea2099048fcfc0b5d7934d8b90f48 (diff)
Simplify error handling in CSysShExec::execute
Change-Id: I6c9723d67eeda6deea088ac28b843628a5b3200f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169867 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/source/win32/SysShExec.cxx46
1 files changed, 11 insertions, 35 deletions
diff --git a/shell/source/win32/SysShExec.cxx b/shell/source/win32/SysShExec.cxx
index 57e59f96b6f0..fb69b9897c73 100644
--- a/shell/source/win32/SysShExec.cxx
+++ b/shell/source/win32/SysShExec.cxx
@@ -281,47 +281,23 @@ void SAL_CALL CSysShExec::execute( const OUString& aCommand, const OUString& aPa
if ((info.dwAttributes & SFGAO_LINK) == 0) {
break;
}
- sal::systools::COMReference<IShellLinkW> link;
try
{
- link.CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER);
+ sal::systools::COMReference<IShellLinkW> link(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER);
+ sal::systools::COMReference<IPersistFile> file(link, sal::systools::COM_QUERY_THROW);
+ sal::systools::ThrowIfFailed(file->Load(path, STGM_READ),
+ "IPersistFile.Load failed");
+ sal::systools::ThrowIfFailed(link->Resolve(nullptr, SLR_UPDATE | SLR_NO_UI),
+ "IShellLink.Resolve failed");
+ WIN32_FIND_DATAW wfd;
+ sal::systools::ThrowIfFailed(link->GetPath(path, std::size(path), &wfd, SLGP_RAWPATH),
+ "IShellLink.GetPath failed");
}
catch (sal::systools::ComError& e)
{
throw css::lang::IllegalArgumentException(
- ("XSystemShellExecute.execute, CoCreateInstance failed with "
- + OUString::number(e.GetHresult())),
- {}, 0);
- }
- sal::systools::COMReference<IPersistFile> file;
- try {
- file = link.QueryInterface<IPersistFile>(sal::systools::COM_QUERY_THROW);
- } catch(sal::systools::ComError & e3) {
- throw css::lang::IllegalArgumentException(
- ("XSystemShellExecute.execute, QueryInterface failed with: "
- + o3tl::runtimeToOUString(e3.what())),
- {}, 0);
- }
- HRESULT e2 = file->Load(path, STGM_READ);
- if (FAILED(e2)) {
- throw css::lang::IllegalArgumentException(
- ("XSystemShellExecute.execute, IPersistFile.Load failed with "
- + OUString::number(e2)),
- {}, 0);
- }
- e2 = link->Resolve(nullptr, SLR_UPDATE | SLR_NO_UI);
- if (FAILED(e2)) {
- throw css::lang::IllegalArgumentException(
- ("XSystemShellExecute.execute, IShellLink.Resolve failed with "
- + OUString::number(e2)),
- {}, 0);
- }
- WIN32_FIND_DATAW wfd;
- e2 = link->GetPath(path, SAL_N_ELEMENTS(path), &wfd, SLGP_RAWPATH);
- if (FAILED(e2)) {
- throw css::lang::IllegalArgumentException(
- ("XSystemShellExecute.execute, IShellLink.GetPath failed with "
- + OUString::number(e2)),
+ ("XSystemShellExecute.execute, " + o3tl::runtimeToOUString(e.what())
+ + " with " + OUString::number(e.GetHresult())),
{}, 0);
}
// Fail at some arbitrary nesting depth, to avoid an infinite loop: