Error System¶
EasyLang includes a beginner-friendly error reporting system designed to:
- Explain the error clearly
- Show the exact line and column
- Highlight the mistake with a caret (
^) - Display a small snippet of surrounding code
- Distinguish between Syntax Errors and Runtime Errors
The interpreter’s pretty_error() function ensures errors are visually clean and understandable even for beginners.
Types of Errors¶
EasyLang defines these main categories:
- SyntaxError
- RuntimeError
- NameError (undefined variable)
- TypeError (wrong type usage)
- ModuleError (module loading issues)
- FileError (file handling errors)
- IndexError (list index issues)
- KeyError (invalid dictionary key)
- ValueError (invalid values)
Internally, most of these are wrapped inside the general RuntimeError type with clear message text.
1. Syntax Errors¶
Syntax errors appear when the parser encounters invalid structure.
Example:
we let x == 10
Output:
SyntaxError: Expected '=' (got '==')
1| we let x == 10
^
Common syntax errors include:
- missing brackets
- unknown keywords
- misplaced operators
- missing then or : do
- missing alias in bring statements
- calling functions incorrectly
Example:
if x equals 10 [
Error:
SyntaxError: Expected 'then'
1| if x equals 10 [
^
2. Runtime Errors¶
These occur during execution, after the code is parsed successfully.
Example:
we let x = 10
we let y = z plus 5
Output:
RuntimeError: Undefined variable 'z'
2| we let y = z plus 5
^
Runtime errors include:
- undefined variables
- type mismatches
- calling non-functions
- invalid math operations
- invalid list operations
- invalid file operations
Example:
we let x = "hello" plus 10
Output:
RuntimeError: Unsupported operand types for plus: string and number
3. Name Errors (Undefined Variables)¶
Triggered when a variable isn’t defined in any scope.
Example:
so print foo
Error:
RuntimeError: Undefined variable 'foo'
1| so print foo
^
The interpreter checks:
- local scope
- parent scopes
- global scope
- module scope
If not found, error.
4. Type Errors¶
Triggered when you combine incompatible types.
Examples:
"hello" plus 10
true mul "hi"
Error message:
RuntimeError: Unsupported operand types for plus: string and number
Another example:
we let x = 10
x.upper()
Error:
RuntimeError: Object has no attribute 'upper'
5. Module Errors¶
These occur when importing modules.
File not found:
bring "nope.elangh" as x
Produces:
RuntimeError: Module file 'nope.elangh' not found.
Python module not installed:
bring requests as req
Produces:
RuntimeError: Could not import Python module: requests
Invalid module alias:
bring math
Produces:
SyntaxError: Expected alias after 'as'
6. File Handling Errors¶
Opening a missing file (read mode):
RuntimeError: Could not open file 'data.txt' for reading.
Writing without open file:
writeline f with "hello"
Error:
RuntimeError: File handle 'f' does not exist
Reading into invalid variable:
readline f into 10
Error:
SyntaxError: Expected identifier after 'into'
Closing invalid file:
close unknown_file
Error:
RuntimeError: File handle 'unknown_file' not found
7. Index Errors (Lists)¶
Example:
we let nums = [1, 2, 3]
so print nums[10]
Error:
RuntimeError: List index out of range
8. Key Errors (Dictionaries)¶
Example:
we let user = {"name": "A"}
so print user.age
Error:
RuntimeError: Dictionary key 'age' not found
Error Formatting¶
Every EasyLang error includes:
- Error type
- Descriptive message
- Line number
- Column number
- Code preview
- Caret (^) under the exact location
Example:
RuntimeError: Cannot divide string by number
4| we let x = "hello" div 2
^
This behavior is handled by:
- exception raising inside interpreter
- final formatting via
pretty_error()
Catching Errors (Function-Level Behavior)¶
Functions do not support try/catch yet.
However, errors show the:
- last executed function
- file
- line
Example:
RuntimeError: Undefined variable 'a'
3| return a plus b
^
In function: add
Summary¶
EasyLang’s error system is designed to be:
- clear
- friendly
- visible
- beginner-oriented
- accurate
- helpful
The interpreter shows:
- exact error type
- exact code location
- exact problem description
- highlighted caret indicator
This makes debugging much easier for new programmers.
Next Steps¶
Continue to Types System to learn how Types System work in detail