-
Notifications
You must be signed in to change notification settings - Fork 166
use more exception when statements #520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
use more exception when statements #520
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 2 lines pattern (if + do log) is used everywhere in the codebase, and that (at least, to me) brings consistency and less mental burden while scanning the code.
Changing that in a couple of places only because - as of today - the "do log" is the only instruction remaining in the catch block does not seem to be worth it.
What is the reason for doing it?
from my understanding of exception when statements, they are more efficient since if the when is false, the runtime doesnt need to build the stack trace. |
Hi @SimonCropp
Found it, here. So it looks like you were right, thanks for letting me learn something new! Now I need to balance readability/maintainability VS the perf gain, lemme think a bit about it. |
if u put a newline before the when, then IMO the readability is the same
versus
|
This changes the existing behavior, though. The original implementation not only logs but also always suppresses exceptions. With |
Damn, you're right @Inok ps: maybe an extra |
It's not merged yet, it seems, so don't worry. I'm just warning about consequences 🙂
If the second In the context of logging, using try { ... }
catch (Exception ex) when (LogException(ex))
{
/* empty, never executed */
}
bool LogException(Exception ex)
{
if (logger.IsEnabled(...))
logger.Log(ex);
return false;
} |
No description provided.