M
Marty List
I have a C++ background, I'm new to C#, and I'm trying to clean up someone
else's code:
if(purge)
for(int j = 1; j < 2; j++)
try{
dumpster.Remove(1);
}
catch(Exception e){
WriteEvent(ErrorSource, e.StackTrace, LogType.Error);
}
Question #1: The "for" statement is pointless, since it only executes once,
correct?
Question #2: Should the "if" statement include braces, or will the catch block
execute without them?
If the braces are optional in this case, for clarity I think they should be
there anyway. This is how I would rewrite it, comments?
if(purge){
try{
dumpster.Remove(1);
}
catch(Exception e){
WriteEvent(ErrorSource, e.StackTrace, LogType.Error);
}
}
else's code:
if(purge)
for(int j = 1; j < 2; j++)
try{
dumpster.Remove(1);
}
catch(Exception e){
WriteEvent(ErrorSource, e.StackTrace, LogType.Error);
}
Question #1: The "for" statement is pointless, since it only executes once,
correct?
Question #2: Should the "if" statement include braces, or will the catch block
execute without them?
If the braces are optional in this case, for clarity I think they should be
there anyway. This is how I would rewrite it, comments?
if(purge){
try{
dumpster.Remove(1);
}
catch(Exception e){
WriteEvent(ErrorSource, e.StackTrace, LogType.Error);
}
}