Skip to content

Conversation

SimonCropp
Copy link
Contributor

No description provided.

Copy link
Collaborator

@jodydonetti jodydonetti left a 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?

@SimonCropp
Copy link
Contributor Author

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.

@jodydonetti
Copy link
Collaborator

Hi @SimonCropp

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.

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.

@SimonCropp
Copy link
Contributor Author

if u put a newline before the when, then IMO the readability is the same

catch (Exception exc)
    when (logger?.IsEnabled(LogLevel.Warning) ?? false)

versus

catch (Exception exc)
{
    if (logger?.IsEnabled(LogLevel.Warning) ?? false)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants