Feather2 / documentation / ExitingScripts.md
Exiting Scripts
The defaults configuration prevents script from calling
System.exit()
, because this terminates the entire JVM
(so your application will exit).
The preferred alternative is to call abort()
,
which is part of the Feather runtime. (See class FeatherExtensions
)
abort()
is just shorthand for throw Abort()
.
Abort
extends Throwable
(not Excpetion
).
Stopping Scripts externally
When feather is used as a scripting language within an application, you probably need a mechanism to kill the script (especially if the script has a bug, which causes an endless loop).
Here's some Kotlin pseudocode which runs a script, that can be killed later :
val config = FeatherConfiguration().apply {
// NOTE, the default value is false.
throwWhenInterrupted = true
}
val results = FeatherCompiler( config ).compile( scripts )
val scriptThread = Thread {
// Run the script (not shown here)
}
scriptThread.start()
The script can then be killed using :
scriptThread.interrupt()
When the throwWhenInterrupted
option is set, every feather loop (for
, while
and do while
)
throws an InteruptedException
if Thread.isInterrupted() == true
.
Note. If the script is in an endless loop within a Java library
(i.e. the loop isn't part of a Feather script),
then interrupt()
may not kill the script.