When managed code throws an exception, the runtime passes the HRESULT to the COM client. When unmanaged code returns an error, the HRESULT is converted to an exception, which is then thrown by the runtime. For information about HRESULT values and their corresponding.NET Framework exceptions, see How to: Map HRESULTs and Exceptions. Post by Ashok K Kumar RPCETOOLATE means CoInitializeSecurity has been already called. You will have to trace your code and find out where it is been called. 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.

  1. Hresult Thrown
  2. Hresult Throw
  3. Hresult Throwing
  4. Throw Hresult
Hresult Throw

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)

The base exception class for these kind of exceptions is ExternalException. It has a public ErrorCode property with a constructor to set it. The COMException class' default HRESULT already is 0x80004005 (EFAIL). – Hans Passant Jun 22 '12 at 16:03. The files on that OneDrive site are NOT templates. They are Word documents. The issue almost certainly is that the template from which the NewWordTemplateV16.15.docx document was created, contains, or at some point contained Different First Page and Different Odd and Even headers footers.

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

  • 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)
Hresult Throw
  • 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)
  • bad_array_new_length(C++11)
Hresult Throw
  • 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'
-->

COM methods report errors by returning HRESULTs; .NET methods report them by throwing exceptions. The runtime handles the transition between the two. Each exception class in the .NET Framework maps to an HRESULT.

User-defined exception classes can specify whatever HRESULT is appropriate. These exception classes can dynamically change the HRESULT to be returned when the exception is generated by setting the HResult field on the exception object. Additional information about the exception is provided to the client through the IErrorInfo interface, which is implemented on the .NET object in the unmanaged process.

Hresult Throw

If you create a class that extends System.Exception, you must set the HRESULT field during construction. Otherwise, the base class assigns the HRESULT value. You can map new exception classes to an existing HRESULT by supplying the value in the exception's constructor.

Note that the runtime will sometimes ignore an HRESULT in cases where there is an IErrorInfo present on the thread. This behavior can occur in cases where the HRESULT and the IErrorInfo do not represent the same error.

To create a new exception class and map it to an HRESULT

  1. Use the following code to create a new exception class called NoAccessException and map it to the HRESULT E_ACCESSDENIED.

You might encounter a program (in any programming language) that uses both managed and unmanaged code at the same time. For example, the custom marshaler in the following code example uses the Marshal.ThrowExceptionForHR(int HResult) method to throw an exception with a specific HRESULT value. The method looks up the HRESULT and generates the appropriate exception type. For example, the HRESULT in the following code fragment generates ArgumentException.

The following table provides the common mappings from HRESULT to its comparable exception class in .NET. HRESULT values without explicit mappings are mapped to COMException. The complete up-to-date mapping can be found in the dotnet/runtime repository.

HRESULT.NET exception
COR_E_APPLICATIONApplicationException
COR_E_ARGUMENT or E_INVALIDARGArgumentException
COR_E_ARGUMENTOUTOFRANGEArgumentOutOfRangeException
COR_E_ARITHMETIC or ERROR_ARITHMETIC_OVERFLOWArithmeticException
COR_E_ARRAYTYPEMISMATCHArrayTypeMismatchException
COR_E_BADIMAGEFORMAT or ERROR_BAD_FORMATBadImageFormatException
COR_E_DIRECTORYNOTFOUND or ERROR_PATH_NOT_FOUNDDirectoryNotFoundException
COR_E_DIVIDEBYZERODivideByZeroException
COR_E_DUPLICATEWAITOBJECTDuplicateWaitObjectException
COR_E_ENDOFSTREAMEndOfStreamException
COR_E_ENTRYPOINTNOTFOUNDEntryPointNotFoundException
COR_E_EXCEPTIONException
COR_E_EXECUTIONENGINEExecutionEngineException
COR_E_FIELDACCESSFieldAccessException
COR_E_FILENOTFOUND or ERROR_FILE_NOT_FOUNDFileNotFoundException
COR_E_FORMATFormatException
COR_E_INDEXOUTOFRANGEIndexOutOfRangeException
COR_E_INVALIDCAST or E_NOINTERFACEInvalidCastException
COR_E_INVALIDFILTERCRITERIAInvalidFilterCriteriaException
COR_E_INVALIDOPERATIONInvalidOperationException
COR_E_IOIOException
COR_E_MEMBERACCESSAccessException
COR_E_METHODACCESSMethodAccessException
COR_E_MISSINGFIELDMissingFieldException
COR_E_MISSINGMANIFESTRESOURCEMissingManifestResourceException
COR_E_MISSINGMEMBERMissingMemberException
COR_E_MISSINGMETHODMissingMethodException
COR_E_NOTFINITENUMBERNotFiniteNumberException
E_NOTIMPLNotImplementedException
COR_E_NOTSUPPORTEDNotSupportedException
COR_E_NULLREFERENCE orE_POINTERNullReferenceException
COR_E_OUTOFMEMORY or
E_OUTOFMEMORY
OutOfMemoryException
COR_E_OVERFLOWOverflowException
COR_E_PATHTOOLONG or ERROR_FILENAME_EXCED_RANGEPathTooLongException
COR_E_RANKRankException
COR_E_REFLECTIONTYPELOADReflectionTypeLoadException
COR_E_SECURITYSecurityException
COR_E_SERIALIZATIONSerializationException
COR_E_STACKOVERFLOW orERROR_STACK_OVERFLOWStackOverflowException
COR_E_SYNCHRONIZATIONLOCKSynchronizationLockException
COR_E_SYSTEMSystemException
COR_E_TARGETTargetException
COR_E_TARGETINVOCATIONTargetInvocationException
COR_E_TARGETPARAMCOUNTTargetParameterCountException
COR_E_THREADINTERRUPTEDThreadInterruptedException
COR_E_THREADSTATEThreadStateException
COR_E_TYPELOADTypeLoadException
COR_E_TYPEINITIALIZATIONTypeInitializationException
COR_E_VERIFICATIONVerificationException

To retrieve extended error information, the managed client must examine the fields of the exception object that was generated. For the exception object to provide useful information about an error, the COM object must implement the IErrorInfo interface. The runtime uses the information provided by IErrorInfo to initialize the exception object.

Hresult Throw

If the COM object does not support IErrorInfo, the runtime initializes an exception object with default values. The following table lists each field associated with an exception object and identifies the source of default information when the COM object supports IErrorInfo.

Note that the runtime will sometimes ignore an HRESULT in cases where there is an IErrorInfo present on the thread. This behavior can occur in cases where the HRESULT and the IErrorInfo do not represent the same error.

Hresult
Exception fieldSource of Information from COM
ErrorCodeHRESULT returned from call.
HelpLinkIf IErrorInfo->HelpContext is nonzero, the string is formed by concatenating IErrorInfo->GetHelpFile and '#' and IErrorInfo->GetHelpContext. Otherwise the string is returned from IErrorInfo->GetHelpFile.
InnerExceptionAlways a null reference (Nothing in Visual Basic).
MessageString returned from IErrorInfo->GetDescription.
SourceString returned from IErrorInfo->GetSource.
StackTraceThe stack trace.
TargetSiteThe name of the method that returned the failing HRESULT.

Hresult Throwing

Exception fields, such as Message, Source, and StackTrace are not available for the StackOverflowException.

Throw Hresult

See also