ExceptionResultHelpers.h (1057B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #pragma once 4 #include <exception> 5 #include <AppInstallerLogging.h> 6 7 namespace winrt::Microsoft::Management::Configuration::implementation 8 { 9 template <typename UnitResult> 10 void ExtractUnitResultInformation(std::exception_ptr exc, const UnitResult& unitResult) 11 { 12 try 13 { 14 std::rethrow_exception(exc); 15 } 16 catch (const winrt::hresult_error& hre) 17 { 18 unitResult->Initialize(hre.code(), hre.message()); 19 } 20 catch (const std::exception& ex) 21 { 22 unitResult->Initialize(E_FAIL, AppInstaller::Utility::ConvertToUTF16(ex.what())); 23 } 24 catch (...) 25 { 26 unitResult->Initialize(E_FAIL, hstring{}); 27 } 28 29 AICLI_LOG(Config, Error, << "Unit Processor exception: " << AppInstaller::Logging::SetHRFormat << unitResult->ResultCode() << " [" << AppInstaller::Utility::ConvertToUTF8(unitResult->Description()) << "]"); 30 } 31 }