简体   繁体   中英

Handle SOAP exception cases with several catch blocks

This(*) ObjectLockedException returned from a Java-based web service. I want to catch this specific error on .NET.

I use C#. Can anyone suggest a method for the code below? I mean how can I make it work?

try{
 service.something();

}catch(ObjectLockedException exx)
{
  alert("Hey!, remove the lock");
}
catch
{
//this block is for the rest of the exceptions
}

(*)The Detailed Explnation OF Exception That I want to catch; java.rmi.RemoteException: error while preparing instance QS.TYR.611; nested exception is: xy.zrt.ugy.business.ObjectLockedException: Could not obtain lock for QS.TYR.611

If the "something" operation in your service has a fault contract then there will be a detail type that contains the error information for the fault. Look for FaultContractAttribute in your service interface. Given this type, T , you can catch FaultException<T> .

If there is no fault contract, you'll have to catch FaultException and pick it apart.

It's unlikely that you can catch the nested exception directly... but it ultimately depends on the fault contract.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM