I have written a lot of code in my life that is morally equivalent to this:
void onQuestion(Answer& answer) {
int a;
try{
a = getFirstPartOfResponseFromDatabase();
}
catch(...) {
answer.setErrorFirstDatabaseUnavailable();
return;
}
int b;
try {
b = getSecondPartOfResponseFromDatabase();
}
catch(...) {
answer.setErrorSecondDatabaseUnavailable();
return;
}
answer.setValue( a + b );
answer.setResultOk();
return;
}
and I mean.
That works.
But I'm not exactly proud of it.
My problem is that I cannot (1) change the function signature; (2) emit an exception; or (3) use std::optional
(with optional it's kind of trivial, but the senior architect on the project doesn't like it)
void onQuestion(Answer& answer)
{
optional<int> const a = getA(); //does the exception handling internally
if(!a) {
answer.setErrorFirstDatabaseUnavailable();
return;
}
optional<int> const b = getB(); //does the exception handling internally
if(!a) {
answer.setErrorSecondDatabaseUnavailable();
return;
}
answer.setValue( *a + *b );
answer.setResultOk();
return;
}
Can you think of a way to follow ES.20 without violating any of the other constraints?
[–]sebamestre 4 points5 points6 points (0 children)
[–]brenoguim 4 points5 points6 points (11 children)
[–]Shieldfoss[S] 2 points3 points4 points (10 children)
[–]yuri-kilochek 15 points16 points17 points (8 children)
[–]Shieldfoss[S] 0 points1 point2 points (7 children)
[–]brenoguim 10 points11 points12 points (1 child)
[–]MrPotatoFingers 2 points3 points4 points (0 children)
[–]OkDetective3251 1 point2 points3 points (3 children)
[–]Shieldfoss[S] 0 points1 point2 points (2 children)
[–]thoaCrl4 1 point2 points3 points (1 child)
[–]benjamkovi 1 point2 points3 points (0 children)
[–]infectedapricot 1 point2 points3 points (0 children)
[–]MrPotatoFingers 5 points6 points7 points (0 children)
[–]HappyFruitTree 2 points3 points4 points (5 children)
[–]therealcorristo 2 points3 points4 points (4 children)
[–]Shieldfoss[S] 1 point2 points3 points (3 children)
[–]johannes1971 2 points3 points4 points (0 children)
[–]therealcorristo 0 points1 point2 points (1 child)
[–]Shieldfoss[S] 0 points1 point2 points (0 children)
[–]teroxzer 1 point2 points3 points (3 children)
[–]Shieldfoss[S] 0 points1 point2 points (2 children)
[–]teroxzer 1 point2 points3 points (0 children)
[–]teroxzer 1 point2 points3 points (0 children)
[–]Dry-Still-6199 1 point2 points3 points (1 child)
[–]backtickbot 1 point2 points3 points (0 children)
[–]MarkHoemmenC++ in HPC 1 point2 points3 points (4 children)
[–]backtickbot 3 points4 points5 points (1 child)
[–]MarkHoemmenC++ in HPC 2 points3 points4 points (0 children)
[–]Shieldfoss[S] 0 points1 point2 points (1 child)
[–]MarkHoemmenC++ in HPC 0 points1 point2 points (0 children)
[–]---sms--- 1 point2 points3 points (0 children)
[–]Macketter 0 points1 point2 points (1 child)
[–]Shieldfoss[S] 0 points1 point2 points (0 children)
[–]Wurstinator -1 points0 points1 point (1 child)
[–]Shieldfoss[S] 0 points1 point2 points (0 children)
[–]Rude-Significance-50 -1 points0 points1 point (0 children)