-
Notifications
You must be signed in to change notification settings - Fork 0
Error Handling
HuyHAP edited this page Mar 19, 2026
·
4 revisions
This guide covers try, except, finally, raise, file-oriented with, and how to read LP parser and codegen diagnostics.
- Read Language Basics first.
LP supports string-based raise expressions:
raise "something went wrong"Basic structure:
try:
risky_call()
except:
print("handled")
finally:
print("cleanup")The current runtime uses a generic exception mechanism. Typed except SomeType as err: syntax is parsed, but the current code generation path treats exception handling generically.
LP supports with statements around file handles returned by open().
with open("notes.txt", "w") as f:
f.write("hello\n")The generated C code closes the file automatically at the end of the block.
The current public file surface is:
open(path, mode)file.read()file.write(data)file.close()
LP's parser error output is designed to show:
- the main error message
- nearby source lines
- a highlighted error line
- hints for common mistakes such as missing colons or missing indentation
def main():
try:
raise "broken"
except:
print("handled")
finally:
print("done")
main()def main():
with open("notes.txt", "w") as f:
f.write("LP\n")
with open("notes.txt", "r") as f:
text = f.read()
print(text)
main()def main()
print("missing colon")Expected outcome:
- LP should reject the file.
- The compiler should show the offending line and a hint about the missing colon.
-
except SomeType as err:is parsed, but current exception handling is generic. Do not depend on typed exception objects yet. -
withis currently documented for file handles fromopen(). Treat arbitrary context-manager semantics as unsupported. -
yieldexists in the lexer and AST, but it is not documented as a stable public language feature yet. - If you get
expected indented block, add an indented body or usepass. - If you get
expected ':', inspect the end of the preceding control-flow or declaration line.
Back to Home | GitHub Repo | Issues
- Home
- Installation and Setup
- First Programs
- Language Basics
- Quick Reference
- Troubleshooting
- Known Limitations
- Language Reference
- Expressions and Collections
- Object-Oriented Programming
- Error Handling
- Feature Overview
- Feature Status
- Runtime Modules
- Concurrency and Parallelism
- Parallel and GPU Computing
- Security Overview
- Security Reference
- Security Calling Patterns
- Native ASM is the default backend.
- On Windows, prefer
--gccfor verification. - Docs are written against verified current behavior.