Java – kotlin native is equivalent to system exit(-1)
•
Java
In the following kotlin / JVM program, system Exit (- 1) stop program execution with error exit code:
fun main(args: Array<String>) { if (args.size < 2) { println("too few args!") System.exit(-1) } println("Hello,${args[1]} from ${args[0]}") }
Kotlin / native does not have access to any Java classes, including system So what is the equivalent function of the kotlin / native program to stop executing the program with an error code?
Solution
Using ExitProcess:
import kotlin.system.exitProcess ... exitProcess(exitCode)
Declaration and documentation are in kotlin source code
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码