IMethodReturnMessage.Exception 属性

获取在方法调用期间引发的异常。

**命名空间:**System.Runtime.Remoting.Messaging
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
ReadOnly Property Exception As Exception
用法
Dim instance As IMethodReturnMessage
Dim value As Exception

value = instance.Exception
Exception Exception { get; }
property Exception^ Exception {
    Exception^ get ();
}
/** @property */
Exception get_Exception ()
function get Exception () : Exception

属性值

方法调用的异常对象;或者如果该方法未引发异常,则为 空引用(在 Visual Basic 中为 Nothing)。

异常

异常类型 条件

SecurityException

直接调用方通过接口引用进行调用,它没有基础结构权限。

示例

下面的代码示例显示了一个重写 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
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;
}
virtual IMessage^ Invoke( IMessage^ myMessage ) override
{
   IMethodCallMessage^ myCallMessage = dynamic_cast<IMethodCallMessage^>(myMessage);

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

   return myIMethodReturnMessage;
}
/** @attribute SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.Infrastructure)
 */
 public IMessage Invoke(IMessage myMessage)
 {
     IMethodCallMessage myCallMessage = (IMethodCallMessage)myMessage;
     IMethodReturnMessage myIMethodReturnMessage 
         = RemotingServices.ExecuteMessage(myMarshalByRefObject,
             myCallMessage);

     if (myIMethodReturnMessage.get_Exception() != null) {
         Console.WriteLine(myIMethodReturnMessage.get_MethodName() 
             + " raised an exception.");
     }
     else {
         Console.WriteLine(myIMethodReturnMessage.get_MethodName() 
             + " does not raised an exception.");
     }

     return myIMethodReturnMessage;
 } //Invoke

.NET Framework 安全性

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

IMethodReturnMessage 接口
IMethodReturnMessage 成员
System.Runtime.Remoting.Messaging 命名空间