RuntimeWrappedException 類別

定義

包裝不是衍生自 Exception 類別的例外狀況。Wraps an exception that does not derive from the Exception class. 這個類別無法被繼承。This class cannot be inherited.

public ref class RuntimeWrappedException sealed : Exception
[System.Serializable]
public sealed class RuntimeWrappedException : Exception
type RuntimeWrappedException = class
    inherit Exception
Public NotInheritable Class RuntimeWrappedException
Inherits Exception
繼承
RuntimeWrappedException
屬性

範例

下列程式碼範例示範如何在中String C++擲回物件當做例外狀況, 並使用RuntimeWrappedException物件加以攔截。The following code example demonstrates how to throw a String object as an exception in C++ and catch it using a RuntimeWrappedException object.

using namespace System;
using namespace System::Runtime::CompilerServices;

[assembly:RuntimeCompatibilityAttribute(WrapNonExceptionThrows = true)]; 

void run()
{
    try
    {
        throw gcnew String("This is a string");

    }
    catch(RuntimeWrappedException^ e)
    {
        Console::WriteLine("RuntimeWrappedException caught!");
    }
}

int main()
{
    run();

    return 0;
}

備註

某些語言 (例如C++) 可讓您擲回任何 managed 類型的例外狀況。Some languages, such as C++, allow you to throw exceptions of any managed type. 其他語言 (例如 Microsoft C#和 Visual Basic) 則會要求每個擲回的Exception例外狀況都衍生自類別。Other languages, such as Microsoft C# and Visual Basic, require that every thrown exception be derived from the Exception class. 為了維持語言之間的相容性, common language runtime (CLR) 會Exception RuntimeWrappedException在物件中包裝不是衍生自的物件。To maintain compatibility between languages, the common language runtime (CLR) wraps objects that do not derive from Exception in a RuntimeWrappedException object.

您可以使用RuntimeCompatibilityAttribute類別來指定是否應該在元件的 catch 區塊和例外狀況篩選準則中包裝例外狀況。You can use the RuntimeCompatibilityAttribute class to specify whether exceptions should appear wrapped inside catch blocks and exception filters for an assembly. 許多語言編譯器 (包括 Microsoft C#和 Visual Basic 編譯器) 預設會套用此屬性來指定換行行為。Many language compilers, including the Microsoft C# and Visual Basic compilers, apply this attribute by default to specify the wrapping behavior.

請注意, 即使您使用RuntimeCompatibilityAttribute類別來指定不想要包裝例外狀況, 執行時間仍會包裝例外狀況。Note that the runtime still wraps exceptions even if you use the RuntimeCompatibilityAttribute class to specify that you do not want them wrapped. 在此情況下, 例外狀況只會在 catch 區塊或例外狀況篩選器內解除包裝。In this case, exceptions are unwrapped only inside catch blocks or exception filters.

建構函式

RuntimeWrappedException(Object)

屬性

Data

取得提供例外狀況之其他使用者定義相關資訊的索引鍵/值組集合。Gets a collection of key/value pairs that provide additional user-defined information about the exception.

(繼承來源 Exception)
HelpLink

取得或設定與這個例外狀況相關聯的說明檔連結。Gets or sets a link to the help file associated with this exception.

(繼承來源 Exception)
HResult

取得或設定 HRESULT,它是指派給特定例外狀況的編碼數值。Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception.

(繼承來源 Exception)
InnerException

取得造成目前例外狀況的 Exception 執行個體。Gets the Exception instance that caused the current exception.

(繼承來源 Exception)
Message

取得描述目前例外狀況的訊息。Gets a message that describes the current exception.

(繼承來源 Exception)
Source

取得或設定造成錯誤的應用程式或物件的名稱。Gets or sets the name of the application or the object that causes the error.

(繼承來源 Exception)
StackTrace

取得呼叫堆疊上即時運算框架的字串表示。Gets a string representation of the immediate frames on the call stack.

(繼承來源 Exception)
TargetSite

取得擲回目前例外狀況的方法。Gets the method that throws the current exception.

(繼承來源 Exception)
WrappedException

取得 RuntimeWrappedException 物件所包裝的物件。Gets the object that was wrapped by the RuntimeWrappedException object.

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetBaseException()

在衍生類別中覆寫時,傳回一或多個後續的例外狀況的根本原因 ExceptionWhen overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions.

(繼承來源 Exception)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetObjectData(SerializationInfo, StreamingContext)

使用與例外狀況相關的資訊來設定 SerializationInfo 物件。Sets the SerializationInfo object with information about the exception.

GetType()

取得目前執行個體的執行階段類型。Gets the runtime type of the current instance.

(繼承來源 Exception)
MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

建立並傳回目前例外狀況的字串表示。Creates and returns a string representation of the current exception.

(繼承來源 Exception)

事件

SerializeObjectState

當例外狀況序列化,以建立包含例外狀況相關序列化資料的例外狀況狀態物件時,就會發生此事件。Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception.

(繼承來源 Exception)

適用於