내 코드에 오류 처리를 넣고 싶습니다. 나는 다음과 같은 예를 들어 그것을 할 방법을 알아낼 수 없습니다 : 'float 메서드'에 대해 null을 반환하는 방법 - 오류 처리
public class DataPoints
{
public PointF[] RawData {get; set;} //raw measurement pairs
public float xMax; //max value on X axis
public float yMax; //max value on Y axis
public float GetMaxX()
{
if(RawData == null)
{
throw new NullReferenceException();
return null; //THIS does not compile! I want to exit the method here
}
//DO other stuff to find max X
return MAX_X; //as float
}
}
그래서 생각이, 내가
RawData
가 이미 설정 한 다음
GetMaxX()
방법으로 물건의 나머지 부분을 할 경우 확인해야합니다. 이것은 좋은 습관입니까? 이 경우 당신은 무엇을 할 것입니까?
은 여기 (null의 유효하지 않은)는 부동 소수점 값을 반환 할 것으로 예상 – V4Vendetta