20 lines
1013 B
Markdown
20 lines
1013 B
Markdown
## 4.4. Exceptions
|
|
|
|
Exceptions in AVAP allow for the handling of errors or exceptional conditions. An exception is raised when an error is detected; it can be handled by the surrounding code block or by any code block that directly or indirectly invoked the block where the error occurred.
|
|
|
|
The AVAP interpreter raises an exception when it detects a runtime error. An AVAP program can also explicitly raise an exception using the `raise` statement. Exception handlers are specified with the `try ... except` statement.
|
|
|
|
Example of exception handling:
|
|
|
|
```javascript
|
|
try()
|
|
addVar(10 / 0, result)
|
|
except()
|
|
addResult("Cannot divide by zero.")
|
|
end()
|
|
```
|
|
|
|
In this example, if a division by zero occurs, a `ZeroDivisionError` exception is raised and handled by the `except` block.
|
|
|
|
This structure ensures that AVAP programs execute in a sequential and predictable manner, without advanced dynamic or deferred execution features, maintaining simplicity and clarity in name binding and import handling.
|