IMethodReturnMessage.Exception 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取在方法调用期间引发的异常。
public:
property Exception ^ Exception { Exception ^ get(); };
public Exception Exception { get; }
public Exception Exception { [System.Security.SecurityCritical] get; }
member this.Exception : Exception
[<get: System.Security.SecurityCritical>]
member this.Exception : Exception
Public ReadOnly Property Exception As Exception
属性值
方法调用的异常对象;或者如果该方法未引发异常,则为 null
。
- 属性
例外
直接调用方通过引用接口进行调用,且没有基础结构权限。
示例
以下示例代码显示了一个自定义代理,该代理重写 RealProxy.Invoke 以编写返回消息信息,包括该方法是否引发异常。
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;
}
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;
}
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