Thanks for your reply! It does not seem to work. I...
# announcements
a
Thanks for your reply! It does not seem to work. I want to add a getEnv method, which throws an Exception if the environment variable does not exists.
h
Define a top-level function
👆 1
Something like this:
Copy code
fun getEnv(key: String) = when {
    System.getenv().containsKey(key) -> System.getenv(key)
    else -> throw Exception("w/e exception you want")
}
That's how
println
is implemented. On the JVM it's just a top-level function wrapping
System.out.println
s
I would probably prefer something like
Copy code
System.getenv(key) ?: throw Exception("missing env $key")
👍 1