throw IllegalArgumentException 대신 require() (+ check)

0

Kotlin

목록 보기
23/32

if(list.isEmtpy) { throw IllegalArgumentException }
라는 코드를 만들었더니 detekt에서
Use require() instead of throwing an IllegalArgumentException. [UseRequire]

require() 라는 함수를 쓰란다.

require(list.isNotEmpty()) -> list.isNotEmtpy가 false일 때, 즉 list.isEmpty 일 때 IllegalArgumentException 예외를 던지는 것임.

if(list.isEmtpy) { throw IllegalArgumentException }
-> require(list.isNotEmpty())

  • IllegalArgumentException -> require()
  • IllegalStateException -> check()

메시지도 넣어줄 수 있다.

참고

profile
백엔드를 공부하고 있습니다.

0개의 댓글