0

Can you help me add Try Catch in this method that return exception of the RestSharp, please?

public IRestResponse<CurrentAccountDocument> PostCurrentAccountDocument(CurrentAccountDocument currentAccountDocument)
    {
        var client = new RestClient(url);

        var request = new RestRequest(uri, Method.POST);
        request.AddHeader("Authorization", $"{Hooks.ResponseGetToken.Data.TokenType} {Hooks.ResponseGetToken.Data.AccessToken}");
        request.AddJsonBody(currentAccountDocument);

        return client.Execute<CurrentAccountDocument>(request);
    }
  • 1
    For context, can you tell us whether you've used `try catch` before in the past? – mjwills Jan 17 '20 at 12:01
  • I've never used. – Adriano Fukuda Jan 17 '20 at 12:09
  • 1
    @AdrianoFukuda Take some time and review the following documentation to get a better understanding https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/try-catch – Nkosi Jan 17 '20 at 12:14
  • What are you trying to do ? Do you want to catch all exceptions or just one from RestSharp? Please elaborate – rak007 Jan 17 '20 at 12:15
  • @rak007 just one from RestSharp. According to documentation of the Page of the Rest Sharp http://restsharp.org/usage/exceptions.html – Adriano Fukuda Jan 17 '20 at 12:20
  • 1
    Does this answer your question? [How can I catch exceptions with RestSharp](https://stackoverflow.com/questions/31222768/how-can-i-catch-exceptions-with-restsharp) – rak007 Jan 17 '20 at 12:23
  • 1
    Stack Overflow doesn't exist to teach you basic programming concepts that you can learn from using a search engine. Once you've learned them, try to apply them, and if you have a problem with the application, post a question. – Ian Kemp Jan 17 '20 at 12:56

0 Answers0