MissingMethodException.Message 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得顯示類別名稱、方法名稱和遺漏方法簽章的文字字串。 這個屬性是唯讀的。
public:
virtual property System::String ^ Message { System::String ^ get(); };
public override string Message { get; }
member this.Message : string
Public Overrides ReadOnly Property Message As String
屬性值
錯誤訊息字串。
範例
下列範例示範 Message 屬性。 此程式碼範例是針對 類別提供的較大範例的 MissingMethodException 一部分。
try
{
// Attempt to call a static DoSomething method defined in the App class.
// However, because the App class does not define this method,
// a MissingMethodException is thrown.
App::typeid->InvokeMember("DoSomething", BindingFlags::Static |
BindingFlags::InvokeMethod, nullptr, nullptr, nullptr);
}
catch (MissingMethodException^ ex)
{
// Show the user that the DoSomething method cannot be called.
Console::WriteLine("Unable to call the DoSomething method: {0}",
ex->Message);
}
try
{
// Attempt to call a static DoSomething method defined in the App class.
// However, because the App class does not define this method,
// a MissingMethodException is thrown.
typeof(App).InvokeMember("DoSomething", BindingFlags.Static |
BindingFlags.InvokeMethod, null, null, null);
}
catch (MissingMethodException e)
{
// Show the user that the DoSomething method cannot be called.
Console.WriteLine("Unable to call the DoSomething method: {0}", e.Message);
}
try
// Attempt to call a static DoSomething method defined in the App class.
// However, because the App class does not define this method,
// a MissingMethodException is thrown.
typeof<App>.InvokeMember("DoSomething", BindingFlags.Static ||| BindingFlags.InvokeMethod, null, null, null)
|> ignore
with :? MissingMethodException as e ->
// Show the user that the DoSomething method cannot be called.
printfn $"Unable to call the DoSomething method: {e.Message}"
Try
' Attempt to call a static DoSomething method defined in the App class.
' However, because the App class does not define this method,
' a MissingMethodException is thrown.
GetType(App).InvokeMember("DoSomething", BindingFlags.Static Or BindingFlags.InvokeMethod, _
Nothing, Nothing, Nothing)
Catch e As MissingMethodException
' Show the user that the DoSomething method cannot be called.
Console.WriteLine("Unable to call the DoSomething method: {0}", e.Message)
End Try
備註
如果未在建構物件時指定類別名稱,則會傳回繼承自基類的預設文字字串。
這個屬性會 Message 覆寫 。 錯誤訊息應當地語系化。