I'm using sonarlint with C#. Something strange happens when I write two try..catch
blocks that catch
blocks do a same thing, like this:
try
{
// Sth
}
catch (Exception ex)
{
// Log sth else
logger.LogError(ex.ToString());
}
try
{
// Sth else
}
catch (Exception ex)
{
// Log sth else
logger.LogError(ex.ToString());
}
It suggests me to combine these two blocks in a single one, maybe like this
try
{
// Sth
// Sth else
}
catch (Exception ex)
{
// Log sth else
logger.LogError(ex.ToString());
}
but obviously this will not do the same thing, because the part // Sth else
will not be executed if exception happens in // Sth
part.
What is going on here? Am I making a mistake or it is on sonarlint?