2024-06-21

This commit is contained in:
2024-06-21 15:01:25 +09:00
commit b5f6bbb1e0
41 changed files with 1895 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
# 예외
코틀린에는 'Checked exception'이 없습니다. 따라서, 자바와 달리, 의무적으로 예외를 처리할 필요가 없습니다.
## 예외 발생
```kotlin
throw Exception("Oops!")
```
## 예외 처리
```kotlin
try {
// ...
} catch(e: SomeException) {
// ...
} finally {
// ...
}
```
`try` 구문도 표현식이므로 값을 반환할 수 있습니다.
```kotlin
val a: Int? = try {
input.toInt()
} catch (e: NumberFormatException) {
null
}
```