| title | Platform::Exception Class | Microsoft Docs | ||||
|---|---|---|---|---|---|
| ms.custom | |||||
| ms.date | 12/30/2016 | ||||
| ms.prod | windows-client-threshold | ||||
| ms.technology | |||||
| ms.reviewer | |||||
| ms.suite | |||||
| ms.tgt_pltfrm | |||||
| ms.topic | language-reference | ||||
| f1_keywords |
|
||||
| dev_langs |
|
||||
| helpviewer_keywords |
|
||||
| ms.assetid | ca1d5a67-3a5a-48fe-8099-f9c38a2d2dce | ||||
| caps.latest.revision | 6 | ||||
| author | ghogen | ||||
| ms.author | ghogen | ||||
| manager | ghogen |
Represents errors that occur during application execution. Custom exception classes can't be derived from Platform::Exception. If you require a custom exception, you can use Platform::COMException and specify an app-specific HRESULT.
public ref class Exception : Object, IException, IPrintable, IEquatable The Exception class inherits from the Object class and the IException, IPrintable, and IEquatable interfaces.
The Exception class also has the following kinds of members.
| Member | Description |
|---|---|
| Exception::Exception | Initializes a new instance of the Exception class. |
The Exception class inherits the Equals(), Finalize(),GetHashCode(),GetType(),MemberwiseClose(), and ToString() methods from the Platform::Object Class. The Exception class also has the following method.
| Member | Description |
|---|---|
| Exception::CreateException | Creates an exception that represents the specified HRESULT value. |
The Exception class also has the following properties.
| Member | Description |
|---|---|
| Exception::HResult | The HRESULT that corresponds to the exception. |
| Exception::Message | A message that describes the exception. This value is read-only and cannot be modified after the Exception is constructed. |
Minimum supported client: [!INCLUDEwin8]
Minimum supported server: [!INCLUDEwinserver8]
Namespace: Platform
Metadata: platform.winmd
Creates a Platform::Exception^ from a specified HRESULT value.
Exception^ CreateException(int32 hr)
Exception^ CreateException(int32 hr, Platform::String^ message) hr
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.
message
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.
Intializes a new instance of the Exception class.
Exception(int32 hresult)
Exception(int32 hresult, ::Platform::String^ message) hresult
The error HRESULT that is represented by the exception.
message
A user-specified message, such as prescriptive text, that is associated with the exception. In general you should prefer the second overload in order to provide a descriptive message that is as specific as possible about how and why the error has occurred.
The HRESULT that corresponds to the exception.
public:property int HResult { int get();} An HRESULT value.
Most exceptions start out as COM errors, which are returned as HRESULT values. C++/CX converts these values into Platform::Exception^ objects, and this property stores the value of the original error code.
Message that describes the error.
public:property String^ Message; In exceptions that originate in the Windows Runtime, this is a system-supplied description of the error.
In [!INCLUDEwin8], this property is read-only because exceptions in that version of the Windows Runtime are transported across the ABI only as HRESULTS. In [!INCLUDEwin81], richer exception information is transported across the ABI and you can provide a custom message that other components can access programmatically. For more information, see Exceptions (C++/CX).