TGViewer
Android Good Reads Android Good Reads @droidgr · 4.03K subscribers
Post #2343 3.83K
Android Good Reads Rich Errors в Kotlin 2.4 Анонсировали на KotlinConf. На мой взгляд, классная обертка на замену старому-доброму try-catch. Какие возможные проблемы видите в этом?
Анонсированные Rich Errors все ближе

В статье о том как к этому подготовиться, ну а я предлагаю взглянуть на side-by-side пример:

Было

fun loadConfig(path: Path): Result<Config> =
runCatching { fileSystem.readBytes(path) }
.mapCatching { bytes -> parseConfig(bytes) }
.recover { e ->
if (e is NoSuchFileException) defaultConfig() else throw e
}

fun useConfig(path: Path) {
loadConfig(path)
.onSuccess { cfg -> startApp(cfg) }
.onFailure { e ->
when (e) {
is NoSuchFileException -> showMissingConfigWarning()
is ConfigFormatException -> showConfigParseError(e)
else -> showGenericError(e)
}
}
}


Стало

// Rich errors
// Define error variants (could be data objects/classes in your domain)
data object IoFailure
data class ParseFailure(val details: String)

fun loadConfig(path: Path): Config | IoFailure | ParseFailure

fun useConfigRich(path: Path) {
when (val r = loadConfig(path)) {
is Config -> startApp(r)
is IoFailure -> showMissingConfigWarning()
is ParseFailure -> showConfigParseErrorMessage(r.details)
}
}
  • 🔥 18
  • ❤ 4
  • 🥰 4
More from @droidgr
  1. Sep 8, 2026🛠 Podlodka Android Crew: Android × AI: новый workflow разработки С 21 по 25 сентября прой…
  2. Aug 6, 2026Если вам всё ещё интересна мобильная разработка, рекомендую подписаться на канал Kotlin Ad…
  3. Aug 4, 2026Post #2504
  4. Jul 26, 2026Как я играю в экосистему продуктов Наиболее близка мне сейчас тема ухода за животными. Я м…
  5. Jul 26, 2026Привет! Как вы могли заметить, я более не помогаю вести данный канал. Если вам понравилось…
  6. Jun 10, 2026Немного про продуктивность без AI. Старый добрый помодоро таймер, но ужесточенный трекинго…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →