My code just looks like this:
try
{
foo();
}
catch (SecurityTokenValidationException ex)
{
Logger.ErrorFormat(ex.Message, ex);
return null;
}
catch (SignatureVerificationFailedException ex)
{
Logger.ErrorFormat(ex.Message, ex);
return null;
}
But the code analysis reports "Avoid Excessive Complexity"
Any pointers ?
If you are using C# 6 you can restrict the handling to your two types with exception filtering:
try
{
foo();
}
catch (Exception ex) when (ex is SecurityTokenValidationException || ex is SignatureVerificationFailedException)
{
Logger.ErrorFormat(ex.Message, ex);
return null;
}
So you don't have to potentially catch other sub types of SecurityTokenException by mistake.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With