Kotlin

Kotlin

Made by DeepSource

The main method should not throw exceptions KT-W1007

Anti-pattern
Major

Avoid throwing exceptions within the main method.

This rule reports all exceptions that are thrown in a main method. An exception should only be thrown if it can be handled by a "higher" function.

Since main is usually at the top of the call stack, there is nothing else above main to catch any exceptions. Any exceptions that are explicitly thrown should always be caught elsewhere.

Bad Practice

fun main(args: Array<String>) {
    // ...
    throw IOException() // exception should not be thrown here
}

Recommended

Don't throw exceptions in the main method.