일부 로깅을 수행 할 메소드를 꾸밀 수있는 방법이 있습니까? 그렇다면 무조건적으로 예외를 throw 할 수 있습니까? 나는이 같은 코드가메소드를 표시하는 방법은 무조건 throw됩니까?
:
void foo(out int x)
{
if(condition()) { x = bar(); return; }
// compiler complains about x not being set yet
MyMethodThatAlwaysThrowsAnException("missed something.");
}
어떤 제안 :이처럼를 작성하려고하면
void foo(out int x)
{
if(condition()) { x = bar(); return; }
// notice that x is not yet set here, but compiler doesn't complain
throw new Exception("missed something.");
}
을 나는 문제를 얻을? 감사.
어떤 문제가 있습니까? –
"x는 특성을 가지고 있으며 아직 메서드의 끝에 설정되지 않았습니다" – k0dek0mmand0
혼란 스럽습니다 - x가 설정되고 반환 될 때 throw되지 않으면 무조건 throw되는 방식 – Matt