일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- Streaming
- Android
- ASMR
- 좋은글필사하기
- Freesound
- 공부집중
- Flutter
- 코틀린
- bash
- Firebase
- 장자명언
- Linux
- 이모지
- 공자명언
- 벤자민플랭클린
- 소울칼리버6
- DART
- kotlin
- FSM
- 명심보감
- androidx
- jetpack compose
- 파이썬
- 이모지메모
- 넷플릭스
- Coroutine
- recyclerview
- 오픈소스
- 1인개발자
- 명언모음
Archives
- Today
- Total
Vintage appMaker의 Tech Blog
[kotlin 배우기 github] 13. 예외처리 본문
- 예외처리인 try/catch문은 자바와 많이 비슷하다.
- 예외객체가 java의 객체와 동일하다.
- 코틀린에서는 try catch를 반드시 할 필요가 없다.
try{
} catch(e: 각종Exception){
} finally {
}
import java.io.BufferedReader
import java.io.FileReader
/**
* Created by snake on 17. 5. 23.
*/
fun main(args : Array<String>){
// java와 흡사하다. 그러나 checked excpetion을 지원안함.
// 즉, try catch를 강제적으로 할 필요가 없다는 말임.
// 그것보다는 알아서 방어코드를 만들라는 것이 kotlin 철학임.
try{
13 / 0;
} catch(e: Exception){
println(e);
} finally {
println("마지막 수행.")
}
var zerodivided = 13 / 0;
println(zerodivided)
}
// try catch를 강제하지 않았을 뿐, 방어코드는 필요하다.
fun no_checked_exception(){
// java 코드 자동컨버팅
// try {
// val `in` = BufferedReader(FileReader(args[0]))
// var s: String?
//
// s = `in`.readLine()
// while (s != null) {
// println(s)
// s = `in`.readLine()
// }
// `in`.close()
// } catch (e: IOException) {
// System.err.println(e) // 에러가 있다면 메시지 출력
// System.exit(1)
// }
//
// kotlin은 try .. catch문을 반드시 할필요가 없다. checked exception을 지원안함!!
// ㅜㅜ
val `in` = BufferedReader(FileReader("file경로명"))
var s: String?
s = `in`.readLine()
while (s != null) {
println(s)
s = `in`.readLine()
}
`in`.close()
}
kotlin 배우기 - github 예제 - Google Play 앱
안드로이드 개발 공식언어로 kotlin이 추가되었습니다. 안드로이드 개발자 입장에서는 배워야 하지만, 그것도 시간과 노력이 필요해서 쉽지가 않습니다. 그런 개발자들을 위해 kotlin의 필수사항
play.google.com
'강좌, 연재 > 앱으로 배우는 kotlin' 카테고리의 다른 글
[kotlin 배우기 github] 15. 오버로딩, 오버라이딩 (0) | 2020.11.19 |
---|---|
[kotlin 배우기 github] 14. class (0) | 2020.11.19 |
[kotlin 배우기 github] 12. collections (0) | 2020.11.19 |
[kotlin 배우기 github] 11. label (0) | 2020.11.19 |
[kotlin 배우기 github] 10. 제어문 (0) | 2020.11.18 |
Comments