From ffa97f45736599f8b9322f013f0755e311fc0ee7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Przemys=C5=82aw=20Pluta?= Date: Sun, 22 Mar 2020 16:17:23 +0100 Subject: [PATCH] Created Error handling (markdown) --- Error-handling.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Error-handling.md 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