MinitScript supports exceptions, which are categorized as flow control.
Exceptions are about 3 things. Trying to do some work, that can issue a exception, which means a failure in logic, and catching the exception. Third is also how to throw exceptions.
Exceptions do not need to be catched at the level of the throw statement, it can also be catched a level higher from a calling function.
module
function: module1Init()
console.printLine("-----------------")
console.printLine("init")
console.printLine("-----------------")
# initialize our array
$array = []
try
# reading data.txt into an array
$array = filesystem.getContentAsStringArray(".", "data.txt")
# filesystem.getContentAsStringArray() would throw an exception if data.txt does not exist
# in this case the following functions would not be executed anymore
# the script would jump into catch block
# and we would not see this message
console.printLine("data.txt: read file into memory");
catch ($exception)
console.printLine("An error occurred: " + $exception)
# print the stack trace
console.printLine(stackTrace())
end
end
module;
function: module1Init()
# this throws an exception with the string argument "not implemented"
# the exception can be catched at a higher level
throw("not implemented")
end
use: module_1.tscript
use: module_2.tscript
use: module_3.tscript
# main
function: main()
console.printLine("---------")
console.printLine("Nothing")
console.printLine("---------")
console.printLine()
# initialize modules, which can load data from files or databases, or computing some values, ...
try
# if any of the module initializations throw an unhandled exception, the exception will be handled here in catch block. then the script will stop.
module1Init()
module2Init()
module3Init()
catch ($exception)
# ahhhhh! one initialization failed!
console.printLine("An error occurred: " + $exception)
# print the stack trace
console.printLine(stackTrace())
end
end
- Syntax
- Data types, variables and constants
- Flow control - if, elseif and else
- Flow control - switch, case and default
- Flow control - forTime, forCondition, for and forEach
- Flow control - exceptions
- Functions
- Lambda functions
- Classes
- Modules
- Built-in functions
- Built-in classes
- Operators
- Constants
- MinitScript, see README.md
- MinitScript - How to build, see README-BuildingHowTo.md
- MinitScript - How to use, see README-Tools.md
- The Mindty Kollektiv Discord Server