Rule Definition
Property getters must be lightweight accessors that are always safe to call. It is recommended to redesign getters to be methods if exceptions are something you need to throw.
Remediation
Ensure the getter is not stopped by throwing exception.
Violation Code Sample
public int Bar
{
get
{
throw new Exception(); // VIOLATION
}
}
Fixed Code Sample
public int Bar
{
get
{
return 12; // NON VIOLATION
}
}
Reference
https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/property
Related Technologies
Technical Criterion
Programming Practices - Error and Exception Handling
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.