I have this method called Foo()
that has a couple of API calls in its implementation:
Foo(){
string resA, resB, resC;
try{
resA= APICall_A();
resB= APICall_B();
resC = APICall_C();
someOperation(resB);
}
// Catches any exception thrown by any API Call
catch(Exception ex){
throw new Exception("API Call failed", ex)
}
}
How could I implement a clean retry logic on the APICall_B()
ONLY if it throws an exception where Exception.HResult = 0x8007001F
?
Changing the catch block to something like:
catch(Exception ex){
if(ex.HResult == 0x8007001F){
resB = APICall_B();
resC = APICall_C();
someOperation(resB);
}
else{
throw new Exception("API Call failed", ex);
}
}
Seems like such a waste of code. Wondering if there's a better way to do this.
User contributions licensed under CC BY-SA 3.0