diff --git a/Error-handling.md b/Error-handling.md new file mode 100644 index 0000000..0fb169e --- /dev/null +++ b/Error-handling.md @@ -0,0 +1,34 @@ +SMNP language doesn't have any sophisticated error handling mechanism, however, you are still able to raise errors using `throw` statement. +The `throw` construction is inspired by Java language, however instead of +throwing exceptions SMNP language allows you only to throw string values. +When control flow meet `throw` statement, program execution is immediately interrupted +and Execution Error is raised with message passed to `throw` statement. + +Example: +``` +function divide(a: int, b: int) { + if (b == 0) { + throw "You are trying to divide by 0!"; + } + + return a / b; +} +``` +If you try to invoke e.g. `divide(2, 0)` the following error will be raised: +``` +Error +Source: /.../.../scratchpad.mus +Position: line 10, column 15 + +You are trying to divide by 0! + +Stack trace: +[1] ::divide(int, int) +[0] ::() +``` + +SMNP language does not support any equivalent of `try-catch` statements known from +other languages. Because the SMNP is not aimed at building complex systems +and there is simply no need to implement sophisticated error handling system +in simple music, you are actually unable to implement more advanced multi-layer +error handling system. \ No newline at end of file