I have the following reoccurring try/catch pattern in my code. Using a try/catch block to handle any exceptions thrown when calling a method in orionProxy.
async private void doGetContacts()
{
try {
currentContacts = await orionProxy.GetContacts (); // call method in orionProxy
ShowContacts (); // do something after task is complete
}
catch (Exception e) {
orionProxy.HandleException (e); // handle thrown exception
}
}
What I would like to write is something like the following.
async private void doGetContacts()
{
currentContacts = await orionProxy.CheckForException(orionProxy.GetContacts ());
ShowContacts (); // do something after task is complete but shouldn't run on exception
}
Any pointers/suggestions? I've tried various forms of Actions/Tasks/Lambdas but nothing will properly trap the exception in orionProxy.CheckForException(?) so ShowContacts doesn't run.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…