Uredi

Deli z drugimi prek


Platform::Exception Class

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.

Syntax

public ref class Exception : Object,    IException,    IPrintable,    IEquatable

Members

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.

Constructors

Member Description
Exception::Exception Initializes a new instance of the Exception class.

Methods

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.

Properties

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.

Requirements

Minimum supported client: Windows 8

Minimum supported server: Windows Server 2012

Namespace: Platform

Metadata: platform.winmd

Exception::CreateException Method

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

Syntax

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

Parameters

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.

Return Value

An exception that represents the error HRESULT.

Remarks

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.

Exception::Exception Constructor

Intializes a new instance of the Exception class.

Syntax

Exception(int32 hresult);
Exception(int32 hresult, ::Platform::String^ message);

Parameters

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.

Exception::HResult Property

The HRESULT that corresponds to the exception.

Syntax

public:
    property int HResult { int get(); }

Property Value

An HRESULT value.

Remarks

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.

Exception::Message Property

Message that describes the error.

Syntax

public:property String^ Message;

Property Value

In exceptions that originate in the Windows Runtime, this is a system-supplied description of the error.

Remarks

In Windows 8, this property is read-only because exceptions in that version of the Windows Runtime are transported across the ABI only as HRESULTS. In Windows 8.1, 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).

See also

Platform namespace