반응형
일부 메서드는 주의해서 호출해야 하지만 ToString과 같은 다른 메서드는 "그냥 작동"할 것으로 예상됩니다. 이러한 메서드에서 예외가 발생하면 호출자의 코드가 예기치 않게 중단될 수 있습니다.
다음 중 하나에서 예외가 발생하면 문제가 발생합니다.
- Event accessors
- Object.Equals
- IEquatable.Equals
- GetHashCode
- ToString
- static constructors
- IDisposable.Dispose
- operator ==, !=, <, >, <=, >=
- implicit cast operators
나쁜 예:
public override string ToString()
{
if (string.IsNullOrEmpty(Name))
{
throw new ArgumentException("..."); // Noncompliant
}
}
반응형