in Education by
How should I handle this exception for API data requester? The Dostuff1,2,3 is 3 different functions that retrieves data from an API. This function is ran every minute. What I want to do is to catch the exception, but not stop the program, and rather let it retry on the next iteration. How should I solve this? I guess I shouldn't be using throw, but the code want me to return something. public async Task Dostuff1,2,3() { try { using (HttpResponseMessage result = await _httpClient.GetAsync(Adrdess)) using (HttpContent content = result.Content) { result.EnsureSuccessStatusCode(); string data = await content.ReadAsStringAsync(); } return data; } catch (Exception ex) { Console.WriteLine("Error"); throw; } } 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
If the return value is what concerns you, then you can return null or new Task(() => string.Empty) since they basically mean that you have no data to return. Now it depends if you have a project with clear requirements where you should always have a default value to return or some other data source if this one is not available, but if you just want the code to compile, you can have a simple return null; there.

Related questions

0 votes
    How should I handle this exception for API data requester? The Dostuff1,2,3 is 3 different functions that ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    How should I handle this exception for API data requester? The Dostuff1,2,3 is 3 different functions that ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    In C#, int and Int32 are the same thing, but I've read a number of times that int is preferred ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 31, 2022 in Education by JackTerrance
0 votes
    In C#, int and Int32 are the same thing, but I've read a number of times that int is preferred ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 29, 2022 in Education by JackTerrance
0 votes
    In C#, int and Int32 are the same thing, but I've read a number of times that int is preferred ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 27, 2022 in Education by JackTerrance
0 votes
    Which of these keywords are used for the block to handle the exceptions generated by try block? (a) try ... Exception Handling of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    How can we handle uncaught exceptions in Node.js?...
asked Jan 25, 2021 in Technology by JackTerrance
0 votes
    I would like to add some features to the Outlook 2010 application. Those features will include: adding a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    This question's answers are a community effort. Edit existing answers to improve this post. It is not ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    Designing a registration form, and I get this error when adding in MessageBoxButtons and MessageBoxIcon. The error ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 15, 2022 in Education by JackTerrance
0 votes
    Designing a registration form, and I get this error when adding in MessageBoxButtons and MessageBoxIcon. The error ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 6, 2022 in Education by JackTerrance
0 votes
    In my tests I need to test what happens when an OracleException is thrown (due to a stored procedure ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 23, 2022 in Education by JackTerrance
0 votes
    We have redesigned the structure to a website which has several business units. Now I want to redirect (301 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    I'm working on an extension (BHO) for Internet Explorer, and having trouble attaching a .NET delegate to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
...