2016년 12월 22일 목요일

.NET에서 Exception 사용하기

출처: http://mattwarren.org/2016/12/20/Why-Exceptions-should-be-Exceptional/

위의 글에서 다음과 같은 결론을 내고 있다.

Conclusion

  1. Rare or Exceptional exceptions are not hugely expensive and they should always be the preferred way of error handling in .NET
  2. If you have code that is expected to fail often (such as parsing a string into an integer), use the TryXXX() pattern
  3. The deeper the stack trace, the more work that has to be done, so the more overhead there is when catching/handling exceptions
  4. This is even more true if you are also fetching the entire stack trace, via the StackTraceproperty. So if you don’t need it, don’t fetch it.
좀 더 요약하면
  1. 예외는 보통 그렇게 비싸지 않다
  2. 자주 일어나는 예외는 TryXXX() 패턴을 사용하라
  3. 깊은 스택 추적을 사용할 때, 오버헤드가 있다
  4. StrackTrace 프로퍼티를 사용하면 오버헤드가 크니 필요없으면 사용하지 마라