
프로젝트를 다시 진행하기로 마음 먹은 나는 그냥 있던 파일들을 다 삭제해 버렸다.
이왕 마음 먹은 거 깔끔하게 다시 지우고 시작하였다.
그리고 커맨드라인을 처리하기 위한 processGeet 함수부터 차근 차근 다시 구현해 주었다.
// geet/processGeet.kt
package geet
import geet.command.geetHelp
import geet.exception.BadRequest
fun processGeet(commandLines: Array<String>): Unit {
if (commandLines.isEmpty() || commandLines[0] == "help") {
geetHelp()
return
}
when (commandLines[0]) {
else -> throw BadRequest("지원하지 않는 명령어입니다.: ${commandLines[0]}")
}
}
커맨드라인이 아무것도 없거나 help인 경우 geetHelp를 호출한다.
또한 명령어가 지원하지 않는 명령어라면 에러를 반환해 줄 생각이다.(아직은 만들어 놓은 것이 없어서 help 외에 무조건 에러를 반환한다.)
// main.kt
import geet.processGeet
fun main(commandLines: Array<String>): Unit {
try {
processGeet(commandLines)
} catch (exception: Exception) {
println(exception.message)
println("\n<<< Exception 스택 추적 >>>")
exception.stackTrace.forEach { println("- ${it}") }
}
}
위와 같이 main에서 try-catch로 에러를 잡아 애러 정보를 출력해준다.
stackTrace는 에러가 발생하고부터 try-catch까지의 위치를 타고 타고 올라가는 정보이다.
여기까지 모습은 아래와 같다.

