3/29/2022

Hresult Throw

Hresult Throw Rating: 4,7/5 8339 votes

You will notice that the exception is thrown from Workbook.Close. Your main code throws some exception. You catch it and throw another exception. Now you call Close and that fails (I do not know why yet). We have similar code, also using UserPrincipal.ChangePassword, that has been working for years but started returning the same exception on February 15, 2016.

Hi, The policy is not causing this problem. Similarly for Ross above, this problem has appeared recently and is not consistent. On the day I reported this problem we found it impossible to change passwords on the two accounts that we tried. System.ArgumentException HResult=0x80070057 Message=An item with the same key has already been added. Key:.14 Source=System.Private.CoreLib StackTrace: at.

-->

A helper function that takes a HRESULT error code, and throws an exception using a C++/WinRT object (or a standard object) that represents that error code.

Throw

Throw Hresult

If the error code is E_OUTOFMEMORY, then std::bad_alloc is thrown. If the error code is a common HRESULT error code, then one of the specialized types derived from winrt::hresult_error is thrown. For example, E_INVALIDARG causes a winrt::hresult_invalid_argument to be thrown. Otherwise, winrt::hresult_error is thrown.

Syntax

Parameters

resultAn HRESULT code that represents the error that was encountered.

Requirements

Minimum supported SDK: Windows SDK version 10.0.17134.0 (Windows 10, version 1803)

Namespace: winrt

Hresult thrown

Header %WindowsSdkDir%Include<WindowsTargetPlatformVersion>cppwinrtwinrtbase.h (included by default)

See also

Hresult Thrown

< cpp‎ error
C++
Language
Standard Library Headers
Freestanding and hosted implementations
Named requirements
Language support library
Concepts library(C++20)
Diagnostics library
Utilities library
Strings library
Containers library
Iterators library
Ranges library(C++20)
Algorithms library
Numerics library
Localizations library
Input/output library
Filesystem library(C++17)
Regular expressions library(C++11)
Atomic operations library(C++11)
Thread support library(C++11)
Technical Specifications
Utilities library
Language support
Type support (basic types, RTTI, type traits)
Library feature-test macros (C++20)
Dynamic memory management
Program utilities
Error handling
Coroutine support(C++20)
Variadic functions
(C++17)
(C++11)
(C++20)
Three-way comparison (C++20)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)(C++20)(C++20)(C++20)(C++20)
General utilities
Date and time
Function objects
Formatting library(C++20)
(C++11)
(C++14)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)
Swap and type operations
(C++20)
(C++14)
(C++11)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
Elementary string conversions
(C++17)
(C++17)
(C++17)
Stacktrace
(C++23)
(C++23)
Error handling
Exception handling
(until C++20)(C++17)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Exception handling failures
(C++11)
(until C++17)
(until C++17)
(C++11)(until C++17)
(until C++17)
Error codes
Error codes
Exception categories
(TM TS)
Assertions
system_error facility
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
std::exception
Member functions
Defined in header <exception>

Provides consistent interface to handle errors through the throw expression.

All exceptions generated by the standard library inherit from std::exception

Hresult Throw

  • future_error(C++11)
  • bad_optional_access(C++17)
  • regex_error(C++11)
  • system_error(C++11)
  • ios_base::failure(C++11)
  • filesystem::filesystem_error(C++17)
  • tx_exception(TM TS)
  • nonexistent_local_time(C++20)
  • ambiguous_local_time(C++20)
  • format_error(C++20)
  • bad_any_cast(C++17)
  • bad_weak_ptr(C++11)
  • bad_function_call(C++11)
Throw
  • bad_array_new_length(C++11)
  • ios_base::failure(until C++11)
  • bad_variant_access(C++17)

[edit]Member functions

constructs the exception object
(public member function)
[virtual]
destroys the exception object
(virtual public member function)[edit]
copies exception object
(public member function)[edit]
[virtual]
returns an explanatory string
(virtual public member function)[edit]
Retrieved from 'https://en.cppreference.com/mwiki/index.php?title=cpp/error/exception&oldid=113349'