Repository: JetBrains/kotlin
File: compiler/cli/cli-runner/src/org/jetbrains/kotlin/runner/runners.kt (Kotlin)

Code before:
import java.net.URLClassLoader
import java.util.jar.Attributes
import java.util.jar.JarFile

class RunnerException(message: String) : RuntimeException(message)

abstract class AbstractRunner : Runner {
    protected abstract val className: String

    protected abstract fun createClassLoader(classpath: List<URL>): ClassLoader

    override fun run(classpath: List<URL>, compilerArguments: List<String>, arguments: List<String>, compilerClasspath: List<URL>) {
        val classLoader = createClassLoader(classpath)

        val mainClass = try {
            classLoader.loadClass(className)
        } catch (e: ClassNotFoundException) {
            throw RunnerException("could not find or load main class $className")
        } catch (e: NoClassDefFoundError) {
            throw RunnerException("could not find or load main class $className")
        }

        val main = try {
            mainClass.getDeclaredMethod("main", Array<String>::class.java)
        } catch (e: NoSuchMethodException) {
            throw RunnerException("'main' method not found in class $className")
        }

        if (!Modifier.isStatic(main.modifiers)) {
            throw RunnerException(
                "'main' method of class $className is not static. " +
                        "Please ensure that 'main' is either a top level Kotlin function, " +
                        "a member function annotated with @JvmStatic, or a static Java method"
            )
        }

        Thread.currentThread().contextClassLoader = classLoader
        val savedClasspathProperty = System.setProperty("java.class.path", classpath.joinToString(File.pathSeparator))

        try {
            main.invoke(null, arguments.toTypedArray())
        } catch (e: IllegalAccessException) {
            throw RunnerException("'main' method of class $className is not public")
        } catch (e: InvocationTargetException) {
            throw e.targetException
        } finally {
            if (savedClasspathProperty == null) System.clearProperty("java.class.path")
            else System.setProperty("java.class.path", savedClasspathProperty)
        }
    }
}

Review comment (suggestion):
This change is needed here to print an error message instead of the exception stack. It is related to [KT-46171](https://youtrack.jetbrains.com/issue/KT-46171), I created that issue earlier today. 

Code after:
import java.net.URLClassLoader
import java.util.jar.Attributes
import java.util.jar.JarFile

class RunnerException(message: String, cause: Throwable? = null) : RuntimeException(message, cause)

abstract class AbstractRunner : Runner {
    protected abstract val className: String

    protected abstract fun createClassLoader(classpath: List<URL>): ClassLoader

    override fun run(classpath: List<URL>, compilerArguments: List<String>, arguments: List<String>, compilerClasspath: List<URL>) {
        val classLoader = createClassLoader(classpath)

        val mainClass = try {
            classLoader.loadClass(className)
        }
        catch (e: ClassNotFoundException) {
            throw RunnerException("could not find or load main class $className")
        } catch (e: NoClassDefFoundError) {
            val message = """
                could not find or load main class $className
                Caused by: $e
            """.trimIndent()
            throw RunnerException(message)
        }

        val main = try {
            mainClass.getDeclaredMethod("main", Array<String>::class.java)
        }
        catch (e: NoSuchMethodException) {
            throw RunnerException("'main' method not found in class $className")
        }

        if (!Modifier.isStatic(main.modifiers)) {
            throw RunnerException(
                    "'main' method of class $className is not static. " +
                    "Please ensure that 'main' is either a top level Kotlin function, " +
                    "a member function annotated with @JvmStatic, or a static Java method"
            )
        }

        Thread.currentThread().contextClassLoader = classLoader
        val savedClasspathProperty = System.setProperty("java.class.path", classpath.joinToString(File.pathSeparator))

        try {
            main.invoke(null, arguments.toTypedArray())
        }
        catch (e: IllegalAccessException) {
            throw RunnerException("'main' method of class $className is not public")
        }