in Education by
Is there any simple way to repeat code in a try/catch block after an exception occurs without using method recursion or goto statements? I'm calling a web service and then pushing that data to a SQL database using Entity Framework, and if the second step fails after the first one succeeds, I'd prefer a simpler or cleaner way to re-try that step rather than recursing the same method (the two steps are in separate methods for this very purpose) or using a goto statement. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
First of all, if you fall into the catch block then it is advisable to do cleanup and logging rather climbing back with goto or recursion. Now to answer your question; Keep your both step within a Transaction block and follow an approach of try enter, which in otherwise trying to execute a block of code until you succeed or for a limited number of times. //Code outline only idea and not production quality code. var timesTried=0 while(timesTried<5) //here I try trying to execute 5 times { using(var tran = new TransactionScope()) { CallMethodA(); CallMethodB(); tran.Complete(); timesTried=6 } timesTried++; }

Related questions

0 votes
    Someone please correct me if I'm wrong, but parsing a yyyy/MM/dd (or other specific formats) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 26, 2022 in Education by JackTerrance
0 votes
    I have an interface that I have defined in C++ which now needs to be implemented in C#. What is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 26, 2022 in Education by JackTerrance
0 votes
    Someone please correct me if I'm wrong, but parsing a yyyy/MM/dd (or other specific formats) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 26, 2022 in Education by JackTerrance
0 votes
    I have an interface that I have defined in C++ which now needs to be implemented in C#. What is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    I want my WPF application to be skinnable, by applying a certain XAML template, and the changes to be ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    Is there an easier way to step through the code than to start the service through the Windows Service ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    Is there an easier way to step through the code than to start the service through the Windows Service ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    Is there an easier way to step through the code than to start the service through the Windows Service ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    Is there an easier way to step through the code than to start the service through the Windows Service ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I have a number of user permissions that are tested throughout my ASP.NET application. These permission ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    What is the diference between those two examples of code? public Test(int x) { List list= new ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
0 votes
    We have some .NET code that does a call out to a COM component (dnsapi.dll) to query whether a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    I want create expression with reflection in c#. I am target script is: using (var service = new ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    Hi Folks i was googling one more hours.i did not find anything relevant, I have text File like ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    I built an OCR application which reads PDF files and OCR's them. I built it using Multi-threading ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
...