| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| Hi All! I think I discovered a possible improvement on .NET Framwork's TRY...CATCH...END TRY statement. I guess most developers might also have been discovered that at some point in their .NET development process but continued to ignore the problem due to their workloads. The word is RETRY. Consider the following... Try '...something Catch e as FileNotFoundException 'correct the error and then ReTry Catch e2 as DirectoryNotFoundException 'correct the error and then ReTry Catch e3 as DriveNotFoundException 'correct the error and then ReTry Catch '<< catch 'unknown' error 'log the error Finally End Try We .NET programmers could use the keyword RETRY in the any of the Catch block to re-execute the code in Try block. If there's another exception thrown, we can evaulate that exception in one of the many Catch blocks until it reached to the 'unkown' exception. So, I propose that a new keyword ReTry should be incorporated in the .NET Framework 2 as an improvement. Feel free to feedback on the idea... -- Nay Myo Aung Chief Visual Software Architect MCP MCSD MCDBA Email: owN0SPAMner @naymyoauN0SPAMng.name [remove NOSPAM s] Homepage: http://hyperdisc.unitec.ac.nz/postgrad/aungn01/ |
|
#2
| |||
| |||
| This is a great idea!! We VB programmers have always had On Error Goto <label> where we could try to fix the error and go back to the start of the block. While we can still do this in .Net I prefer not to as I try to use the framework error handling of Try ... Catch ... End Try. This idea offers some really great flexibility for handling exceptions. I am surprised that they have not mentioned anything like this in their .Net briefs. If your listening MS, please consider this. Robby "Nay Myo Aung" <owNOspaMnerATnaymyoauNOspaMng.name> wrote in message news:uifBpxR2EHA.3452@TK2MSFTNGP14.phx.gbl... > Hi All! > > I think I discovered a possible improvement on .NET Framwork's > TRY...CATCH...END TRY statement. I guess most developers might also have > been discovered that at some point in their .NET development process but > continued to ignore the problem due to their workloads. > > The word is RETRY. > > Consider the following... > > Try > > '...something > > Catch e as FileNotFoundException > > 'correct the error and then > ReTry > > Catch e2 as DirectoryNotFoundException > > 'correct the error and then > ReTry > > Catch e3 as DriveNotFoundException > > 'correct the error and then > ReTry > > Catch '<< catch 'unknown' error > > 'log the error > > Finally > > End Try > > We .NET programmers could use the keyword RETRY in the any of the Catch > block to re-execute the code in Try block. If there's another exception > thrown, we can evaulate that exception in one of the many Catch blocks > until it reached to the 'unkown' exception. > > So, I propose that a new keyword ReTry should be incorporated in the .NET > Framework 2 as an improvement. > > Feel free to feedback on the idea... > > -- > Nay Myo Aung > Chief Visual Software Architect > MCP MCSD MCDBA > > Email: owN0SPAMner @naymyoauN0SPAMng.name [remove NOSPAM s] > Homepage: http://hyperdisc.unitec.ac.nz/postgrad/aungn01/ > |
|
#3
| |||
| |||
| On Fri, 3 Dec 2004 22:36:16 +1300, Nay Myo Aung wrote: > We .NET programmers could use the keyword RETRY in the any of the Catch > block to re-execute the code in Try block. If there's another exception > thrown, we can evaulate that exception in one of the many Catch blocks until > it reached to the 'unkown' exception. > > So, I propose that a new keyword ReTry should be incorporated in the .NET > Framework 2 as an improvement. The first thing that catched my eye when i saw your idea is that it would be dead easy to enter an endless loop with this. Retry again and again without any way to stop this. So you would need to add a counter in each of your catch block to check if this block is not being executed endlessly. Quite messy, isn't it? |
|
#4
| |||
| |||
| Hi, Maybe a facility something like Retry(2) for retrying 2 times might help. Of course, the call to Retry should be specific for the exception type. Regards, Rakesh Rajan "Elp" wrote: > On Fri, 3 Dec 2004 22:36:16 +1300, Nay Myo Aung wrote: > > > We .NET programmers could use the keyword RETRY in the any of the Catch > > block to re-execute the code in Try block. If there's another exception > > thrown, we can evaulate that exception in one of the many Catch blocks until > > it reached to the 'unkown' exception. > > > > So, I propose that a new keyword ReTry should be incorporated in the .NET > > Framework 2 as an improvement. > > The first thing that catched my eye when i saw your idea is that it would > be dead easy to enter an endless loop with this. Retry again and again > without any way to stop this. So you would need to add a counter in each of > your catch block to check if this block is not being executed endlessly. > Quite messy, isn't it? > |
|
#5
| |||
| |||
| > I think I discovered a possible improvement on .NET Framwork's > TRY...CATCH...END TRY statement. I guess most developers might also have > been discovered that at some point in their .NET development process but > continued to ignore the problem due to their workloads. > > The word is RETRY. > > Consider the following... > > Try > '...something > Catch e as FileNotFoundException > 'correct the error and then > ReTry > .... I don't think this is a good idea. There is a good reason why exceptions are called exceptions. They only occur exceptionally. You should not be surprised by FileNotFoundExceptions and similar in your code. The correct way to handle the file not found issue in your example is to do it like this: if (File.Exists(filename)) { // Do something } else { // Try another filename or something.. } Anders Norås http://dotnetjunkies.com/weblog/anoras |
|
#6
| |||
| |||
| Hi, This is true. But in some cases, when you know it's possible some exception might be thrown, and you have implemented code to handle it (in a catch block), you might want to retry what you just did. In those cases, a retry keyword might be better. Regards, Rakesh Rajan "Anders Norås [MCAD]" wrote: > > I think I discovered a possible improvement on .NET Framwork's > > TRY...CATCH...END TRY statement. I guess most developers might also have > > been discovered that at some point in their .NET development process but > > continued to ignore the problem due to their workloads. > > > > The word is RETRY. > > > > Consider the following... > > > > Try > > '...something > > Catch e as FileNotFoundException > > 'correct the error and then > > ReTry > > .... > > I don't think this is a good idea. There is a good reason why exceptions are > called exceptions. They only occur exceptionally. > You should not be surprised by FileNotFoundExceptions and similar in your > code. The correct way to handle the file not found issue in your example is > to do it like this: > > if (File.Exists(filename)) { > // Do something > } else { > // Try another filename or something.. > } > > Anders Norås > http://dotnetjunkies.com/weblog/anoras > > > |
|
#7
| |||
| |||
| Hi Nay Myo Aung, You can have this functionality today int counter = 0; start:; try { File.Open("dummy", FileMode.Open); } catch { counter++; if(counter < 5) goto start; } -- Happy Coding! Morten Wennevik [C# MVP] |
|
#8
| |||
| |||
| Nay, Why would you endless have to catch an error is one them not more than enough The only thing where I can now see where it can be used is in spaghetti code. (And your proposal would than be a legalizing of that) You are not the first one by the way who contributes this to the language.vb newsgroup. Just my thought Cor "Nay Myo Aung" <owNOspaMnerATnaymyoauNOspaMng.name> > Hi All! > > I think I discovered a possible improvement on .NET Framwork's > TRY...CATCH...END TRY statement. I guess most developers might also have > been discovered that at some point in their .NET development process but > continued to ignore the problem due to their workloads. > > The word is RETRY. > > Consider the following... > > Try > > '...something > > Catch e as FileNotFoundException > > 'correct the error and then > ReTry > > Catch e2 as DirectoryNotFoundException > > 'correct the error and then > ReTry > > Catch e3 as DriveNotFoundException > > 'correct the error and then > ReTry > > Catch '<< catch 'unknown' error > > 'log the error > > Finally > > End Try > > We .NET programmers could use the keyword RETRY in the any of the Catch > block to re-execute the code in Try block. If there's another exception > thrown, we can evaulate that exception in one of the many Catch blocks > until it reached to the 'unkown' exception. > > So, I propose that a new keyword ReTry should be incorporated in the .NET > Framework 2 as an improvement. > > Feel free to feedback on the idea... > > -- > Nay Myo Aung > Chief Visual Software Architect > MCP MCSD MCDBA > > Email: owN0SPAMner @naymyoauN0SPAMng.name [remove NOSPAM s] > Homepage: http://hyperdisc.unitec.ac.nz/postgrad/aungn01/ > |
|
#9
| |||
| |||
| this is just messy IMO Ollie "Rakesh Rajan" <RakeshRajan@discussions.microsoft.com> wrote in message news:8DEF66C7-06FD-4564-8146-C2C9C0A188FE@microsoft.com... > Hi, > > Maybe a facility something like > Retry(2) > for retrying 2 times might help. > > Of course, the call to Retry should be specific for the exception type. > > Regards, > Rakesh Rajan > > "Elp" wrote: > > > On Fri, 3 Dec 2004 22:36:16 +1300, Nay Myo Aung wrote: > > > > > We .NET programmers could use the keyword RETRY in the any of the Catch > > > block to re-execute the code in Try block. If there's another exception > > > thrown, we can evaulate that exception in one of the many Catch blocks until > > > it reached to the 'unkown' exception. > > > > > > So, I propose that a new keyword ReTry should be incorporated in the ..NET > > > Framework 2 as an improvement. > > > > The first thing that catched my eye when i saw your idea is that it would > > be dead easy to enter an endless loop with this. Retry again and again > > without any way to stop this. So you would need to add a counter in each of > > your catch block to check if this block is not being executed endlessly. > > Quite messy, isn't it? > > |
|
#10
| |||
| |||
| Hi Cor, Actually, it is not endless. We could put counters or we could have something like ReTry(3) for 3 retries, as pointed out by Rakesh Rajan. The main idea is to eliminate the need to rewrite the code that is already written in the Try block with only a small variation (small enough to be defined through variables). For instance... Try <<TaskA>> Catch Try <<TaskA with small variation>> Catch Try <<TaskA with another small variation>> Catch Try <<TaskA with yet another small variation>> Catch End Try End Try End Try End Try In above example, we need to duplicate the code written in Try block into sub-Try blocks with just small variations. I consider this as a bad practice since more code duplication means, more errors and more maintenance overhead. That's why we need a ReTry statement. I know we can put the reusable code into Sub procedures but sometimes the code is not big enough (or not worth the system overhead) to put it in its own procedure. -- Nay Myo Aung Chief Visual Software Architect MCP MCSD MCDBA Email: owN0SPAMner @naymyoauN0SPAMng.name [remove NOSPAM s] Homepage: http://hyperdisc.unitec.ac.nz/postgrad/aungn01/ "Cor Ligthert" <notmyfirstname@planet.nl> wrote in message news:%2331sudS2EHA.1408@TK2MSFTNGP10.phx.gbl... > Nay, > > Why would you endless have to catch an error is one them not more than > enough > > The only thing where I can now see where it can be used is in spaghetti > code. > (And your proposal would than be a legalizing of that) > > You are not the first one by the way who contributes this to the > language.vb newsgroup. > > Just my thought > > > Cor > > > "Nay Myo Aung" <owNOspaMnerATnaymyoauNOspaMng.name> > >> Hi All! >> >> I think I discovered a possible improvement on .NET Framwork's >> TRY...CATCH...END TRY statement. I guess most developers might also have >> been discovered that at some point in their .NET development process but >> continued to ignore the problem due to their workloads. >> >> The word is RETRY. >> >> Consider the following... >> >> Try >> >> '...something >> >> Catch e as FileNotFoundException >> >> 'correct the error and then >> ReTry >> >> Catch e2 as DirectoryNotFoundException >> >> 'correct the error and then >> ReTry >> >> Catch e3 as DriveNotFoundException >> >> 'correct the error and then >> ReTry >> >> Catch '<< catch 'unknown' error >> >> 'log the error >> >> Finally >> >> End Try >> >> We .NET programmers could use the keyword RETRY in the any of the Catch >> block to re-execute the code in Try block. If there's another exception >> thrown, we can evaulate that exception in one of the many Catch blocks >> until it reached to the 'unkown' exception. >> >> So, I propose that a new keyword ReTry should be incorporated in the .NET >> Framework 2 as an improvement. >> >> Feel free to feedback on the idea... >> >> -- >> Nay Myo Aung >> Chief Visual Software Architect >> MCP MCSD MCDBA >> >> Email: owN0SPAMner @naymyoauN0SPAMng.name [remove NOSPAM s] >> Homepage: http://hyperdisc.unitec.ac.nz/postgrad/aungn01/ >> > > |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.