Exception::CreateException Method
Collapse the table of content
Expand the table of content

Exception::CreateException Method


Creates a Platform::Exception^ from a specified HRESULT value.

Exception^ CreateException(int32 hr)
Exception^ CreateException(int32 hr, Platform::String^ message)


An HRESULT value that you typically get from a call to a COM method. If the value is 0, which is equal to S_OK, this method throws Platform::InvalidArgumentException because COM methods that succeed should not throw exceptions.


A string that describes the error.

An exception that represents the error HRESULT.

Use this method to create an exception out of an HRESULT that is returned, for example, from a call to a COM interface method. You can use the overload that takes a String^ parameter to provide a custom message.

It is strongly recommended to use CreateException to create a strongly-typed exception rather than creating a Platform::COMException that merely contains the HRESULT.


Minimum supported client: Windows 8

Minimum supported server: Windows Server 2012

Namespace: Platform

Metadata: platform.winmd

© 2016 Microsoft