Looking for feedback on this idea I had. I am mostly using C# so I am just thinking about this language but probably this is a .NET framework topic.

Over the years, I have had to implement a clunky-ugly second try catch inside of the catch block in order to perform a "retry" in case of an error.

Since I feel that it is not uncommon for us internet software engineers to need to "retry" an operation, should Microsoft include a new keyword, retry to the language?

I would imagine it would look something like this:
C# Code:
  1. try
  2. {
  3.   // make a call, log the inputs
  4. }
  5. catch (Exception e)
  6. {
  7.   // oops, log the error
  8. }
  9. retry ()
  10. {
  11.   // since we pass in no value, retry this immediately,
  12.   // but only if we hit the previous catch
  13.   // make the same call, log the inputs
  14. }
  15. catch (Exception e)
  16. {
  17.   // I think we still need a catch, log the error
  18. }
  19. retry (1000)
  20. {
  21.   // since we pass in a value, wait 1,000 ms and then try again,
  22.   // but only if we hit the previous catch
  23.   // make the same call, log the inputs
  24. }
  25. catch (Exception e)
  26. {
  27.   // I think we still need a catch, log the error
  28. }
  29. finally
  30. {
  31.   // cleanup and log event
  32. }

As you can see I am big on event logging lol. So the idea is, once you succeed in the try, or the first retry, you skip down to the finally. In the example above, the developer wants 2 retries after the first try. I believe you could have as many as you want, as per the discretion of the developer, during coding time, before compile-time.

I am posting this here because I have always gotten such awesome feedback from this community over the years.

P.S. I decided not to ask for a wait keyword, because I think it's more readable to pass in a value to the retry to signify a wait time. Why milliseconds? I dunno, I kinda like milliseconds.

Thanks,

Dave