exception1 [Kotlin] 예외를 다루는 방법 예외를 다루는 방법 try catch finally 구문 Java private int parseIntOrThrow(@NotNull String str) { try { return Integer.parseInt(str); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("주어진 %s는 숫자가 아닙니다.", str)); } } Kotlin fun parseIntOrThrow(str: String): Int { try { return str.toInt() } catch (e: NumberFormatException) { throw IllegalArgumentException("주어진 ${str}는 숫자가 .. 2022. 7. 6. 이전 1 다음