次の方法で共有


IMethodReturnMessage.Exception プロパティ

メソッドの呼び出し中にスローされた例外を取得します。

ReadOnly Property Exception As Exception
[C#]
Exception Exception {get;}
[C++]
__property Exception* get_Exception();
[JScript]
function get Exception() : Exception;

プロパティ値

メソッド呼び出しに対してスローされた例外オブジェクト。メソッドが例外をスローしなかった場合は null 参照 (Visual Basic では Nothing) 。

例外

例外の種類 条件
SecurityException 直前の呼び出し元は、インターフェイスへの参照を通じて呼び出しを実行します。この呼び出し元には、インフラストラクチャ アクセス許可がありません。

使用例

[Visual Basic, C#, C++] RealProxy.Invoke をオーバーライドして、メソッドが例外をスローしたかどうかなど、返されたメッセージの情報をコンソールに書き込むカスタム プロキシについては、次のコード例を参照してください。

 
Public Overrides Function Invoke(myMessage As IMessage) As IMessage
   Dim myCallMessage As IMethodCallMessage = CType(myMessage, IMethodCallMessage)
   
   Dim myIMethodReturnMessage As IMethodReturnMessage = RemotingServices.ExecuteMessage _
                                                   (myMarshalByRefObject, myCallMessage)
   If Not (myIMethodReturnMessage.Exception Is Nothing) Then
      Console.WriteLine(myIMethodReturnMessage.MethodName + " raised an exception.")
   Else
      Console.WriteLine(myIMethodReturnMessage.MethodName + " does not raised an exception.")
   End If
   
   Return myIMethodReturnMessage
End Function 'Invoke

[C#] 
public override IMessage Invoke(IMessage myMessage)
{
   IMethodCallMessage myCallMessage = (IMethodCallMessage)myMessage;

   IMethodReturnMessage myIMethodReturnMessage =
      RemotingServices.ExecuteMessage(myMarshalByRefObject,myCallMessage);
   if(myIMethodReturnMessage.Exception != null)
      Console.WriteLine(myIMethodReturnMessage.MethodName +
         " raised an exception.");
   else
      Console.WriteLine(myIMethodReturnMessage.MethodName +
         " does not raised an exception.");

   return myIMethodReturnMessage;
}

[C++] 
public:
    IMessage* Invoke(IMessage* myMessage) 
    {
        IMethodCallMessage* myCallMessage = dynamic_cast<IMethodCallMessage*>(myMessage);

        IMethodReturnMessage* myIMethodReturnMessage =
            RemotingServices::ExecuteMessage(myMarshalByRefObject, myCallMessage);
        if (myIMethodReturnMessage->Exception != 0)
            Console::WriteLine("{0} raised an exception.", myIMethodReturnMessage->MethodName);
        else
            Console::WriteLine("{0} does not raise an exception.", myIMethodReturnMessage->MethodName);

        return myIMethodReturnMessage;
    }

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

.NET Framework セキュリティ:

参照

IMethodReturnMessage インターフェイス | IMethodReturnMessage メンバ | System.Runtime.Remoting.Messaging 名前空間