Created Error handling (markdown)

Bartłomiej Przemysław Pluta
2020-03-22 16:17:23 +01:00
parent 73912e6e30
commit ffa97f4573

34
Error-handling.md Normal file

@@ -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] <root>::divide(int, int)
[0] <root>::<entrypoint>()
```
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.