Skip to content

Releases: Scarlet-Pan/try-catch

try-catch 1.0.0 — First Stable Release

17 Nov 00:57

Choose a tag to compare

🎉 try-catch 1.0.0 — First Stable Release

A lightweight, coroutine-safe extension to kotlin.runCatching that enables structured concurrency-aware error handling with type-safe, chainable exception recovery.

✨ Features

  • catchNonCancel: Safely handle non-cancellation exceptions in suspend functions
  • Infix syntax support: Clean, readable chaining like runCatching { ... } catchNonCancel { ... }
  • CancellationException preserved: Never accidentally swallow coroutine cancellation signals
  • Typed exception handlers: Recover from specific exceptions (e.g., IllegalStateException) while letting others propagate
  • Zero dependencies beyond Kotlin and kotlinx.coroutines

🚀 Example

suspend fun fetchConfig(): Config = runCatching {
    remoteConfigService.getConfig()
} catchNonCancel { e: IllegalStateException ->
    Log.w(TAG, "Invalid remote config state.", e)
    defaultConfig
} catchNonCancel { e ->
    Log.w(TAG, "Failed to get config.", e)
    defaultConfig
}

📦 Maven / Gradle

implementation("io.github.scarlet-pan:try-catch:1.0.0")

✅ Compatible with Kotlin 1.6+ and kotlinx.coroutines 1.6.4+
✅ Published to Maven Central
✅ MIT Licensed


🎉 try-catch 1.0.0 — 首个稳定版本

一个轻量级、协程安全的 kotlin.runCatching 扩展库,支持 结构化并发感知的错误处理,提供类型安全、可链式调用的异常恢复能力。

✨ 特性

  • catchNonCancel:在 suspend 函数中安全处理非取消类异常
  • 中缀语法支持:链式调用清晰易读,如 runCatching { ... } catchNonCancel { ... }
  • 保留 CancellationException:绝不会意外吞掉协程取消信号
  • 类型化异常处理器:可针对特定异常(如 IllegalStateException)恢复,其余异常自动向上抛出
  • 零额外依赖:仅需 Kotlin 与 kotlinx.coroutines

🚀 示例

suspend fun fetchConfig(): Config = runCatching {
    remoteConfigService.getConfig()
} catchNonCancel { e: IllegalStateException ->
    Log.w(TAG, "远程配置状态无效。", e)
    defaultConfig
} catchNonCancel { e ->
    Log.w(TAG, "获取配置失败。", e)
    defaultConfig
}

📦 Maven / Gradle

implementation("io.github.scarlet-pan:try-catch:1.0.0")

✅ 兼容 Kotlin 1.6+ 与 kotlinx.coroutines 1.6.4+
✅ 已发布至 Maven Central
✅ MIT 许可证

v1.0.0: Stable release of coroutine-safe, type-safe try-catch extension

07 Nov 13:47
7f18690

Choose a tag to compare

The first stable release of try-catch — a lightweight, coroutine-friendly extension of kotlin.runCatching that brings type-safe exception handling and structured concurrency awareness to your Kotlin/JVM projects.

🌟 Highlights

  • ✅ Chain multiple typed catch blocks like in other languages
  • catchNonCancel: Safely handle exceptions in coroutines without swallowing CancellationException
  • ✅ Fully compatible with kotlinx.coroutines and structured concurrency
  • ✅ Zero dependencies beyond Kotlin stdlib + coroutines
  • ✅ Verified artifact under namespace io.github.scarlet-pan

📦 Installation

Add JitPack to your settings.gradle.kts:

dependencyResolutionManagement {
    repositories {
        mavenCentral()
        maven("https://jitpack.io")
    }
}