|
-
Aug 12th, 2016, 04:45 PM
#1
Thread Starter
PowerPoster
C# keyword enhancement: try / catch / retry / finally
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:
try
{
// make a call, log the inputs
}
catch (Exception e)
{
// oops, log the error
}
retry ()
{
// since we pass in no value, retry this immediately,
// but only if we hit the previous catch
// make the same call, log the inputs
}
catch (Exception e)
{
// I think we still need a catch, log the error
}
retry (1000)
{
// since we pass in a value, wait 1,000 ms and then try again,
// but only if we hit the previous catch
// make the same call, log the inputs
}
catch (Exception e)
{
// I think we still need a catch, log the error
}
finally
{
// cleanup and log event
}
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
Nobody knows what software they want until after you've delivered what they originally asked for.
Don't solve problems which don't exist.
"If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)
2 idiots don't make a genius.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|