Skip to content

適切な箇所に@Throwsをつける #84

@LeoAndo

Description

@LeoAndo
Owner

refs:
https://kotlinlang.org/docs/multiplatform-mobile-upgrade-app.html#connect-http-client
https://zenn.dev/ktrueda/articles/kotlin-jvm-0006

Exceptionをスローするfunctionは@Throws(Exception::class)のようにアノテーションをつけたい。
これによりバイトコードレベルで functionに throws Exceptionが付与される。

import io.ktor.client.call.*
import io.ktor.client.request.*

class Greeting {
    // ...
    @Throws(Exception::class)
    suspend fun greeting(): String {
        val rockets: List<RocketLaunch> =
            httpClient.get("https://api.spacexdata.com/v4/launches").body()
        val lastSuccessLaunch = rockets.last { it.launchSuccess == true }
        return "Guess what it is! > ${platform.name.reversed()}!" +
                "\nThere are only ${daysUntilNewYear()} left until New Year! 🎆" +
                "\nThe last successful launch was ${lastSuccessLaunch.launchDateUTC} 🚀"
    }
}

Activity

added a commit that references this issue on Feb 21, 2023
added a commit that references this issue on Feb 21, 2023
ffc861e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @LeoAndo

      Issue actions

        適切な箇所に@Throwsをつける · Issue #84 · LeoAndo/AndroidGithubSearch