Common runtime errors
Handle a division error
When an input is allowed to be zero, check it or handle the error near the operation that needs it.
divisor = 0
try:
print(10 / divisor)
catch problem:
print('cannot divide by zero')
cannot divide by zero
The division raises before print runs. Atom enters the catch block.
| Symptom | Interpretation and correction |
|---|---|
use spaces for indentation / indentation does not match an earlier line |
Begin suites with spaces and dedent to a previous indentation level. |
expected end of statement |
Finish each statement with a newline. Use delimiters for multiline argument and item lists. |
cannot assign to this binding |
The target is a constant, function declaration, import alias or an inaccessible outer binding. Use a local assignment or a mutable closure cell. |
| Uninitialized variable | A binding exists but execution has not reached the assignment. Initialize every branch that reaches the read. |
signed integer overflow / unsigned integer overflow |
An arithmetic result lies outside i64/u64. Reduce the magnitude or use an appropriate floating representation where rounding is acceptable. |
division by zero |
Guard the divisor before division or remainder. |
numeric conversion is out of range or would lose a fractional value |
A conversion requires the value to fit and, for integer storage, be integral and finite. |
array index is out of bounds |
Append using add, then assign an existing index. |
NaN cannot be a dictionary key |
Use a key with defined equality. |
cannot relocate pinned storage / invalid packed view |
Release active pins before resizing. Obtain a new view after removal. |
unknown module / cannot load module |
Check compile-time features, granted capabilities, spelling and file search paths. |
circular module import |
Remove initialization cycles, for example by factoring shared code into another module. |
task operation timed out |
Check for a producer, consumer or task that has not made progress. Close channels when the last producer is finished. |
call depth limit exceeded |
Check recursion and the VM's call limit. |
native library has been closed |
Keep the library loaded while calling bindings or using associated pointers. |