I have code where there is a catch attempt in a function, and the function hits. 100+ times. The code returns early every time, without clicking on the try catch. This affects performance in Visual Studio. I see the impact of performance.
My code is:
void foo(int a) {
if (a > value) {
return;
}
try {
possibleErrorFunction();
} catch {
}
}
I changed it to:
void foo(int a) {
if (a > value) {
return;
}
bar();
}
void bar() {
try {
possibleErrorFunction();
} catch {
}
}
The second code looks about 10 seconds faster. Is there any elusive explanation for this?
source
share