Statements
while running: step() endfor item in [1, 2, 3]: print(item) endfor i in range(1, 10, 2): print(i) endtry: risky() catch error: print(error.kind) finally: cleanup() endraise {kind: "ConfigError", message: "port required"}return, break, continueStructured error recovery
+Runtime errors are catchable values. A named catch receives a map with
+ kind, message, line, and trace.
+ The optional finally block always runs, including during
+ return, break, and continue.
try:
+ result = 100 / divisor
+catch error:
+ print(error.kind + ":", error.message)
+ result = 0
+finally:
+ print("calculation complete")
+end
+ raise "message" creates a UserError. Raise a map with string
+ kind and message fields to create a named application error.
+ Syntax errors are detected before execution and are not catchable.
Builtins
| Function | Description | |
|---|---|---|
print(...) | Print values, space-separated | |
len(x) | Length of string / list / map / range | |
range(stop) · range(a, b, step) | Integer range | |
sum · enumerate · zip | Iterable aggregation and pairing | |
all · any | Truth tests across an iterable | |
str int float bool repr | Conversions | |
abs floor ceil round sqrt pow | Math | |
min · max | Over arguments or one list | |
| Examples | examples/ | hello, fib, fizzbuzz, terminal_raycast |
| VS Code extension | editors/vscode/ | Syntax highlighting + snippets |
| Dev container | .devcontainer/ | Ready environment for VS Code / Codespaces |
| Tests | tests/ | 108 tests: language + app/EXE builder + parity + PyHope + workspace + Playground + arcade |
| Tests | tests/ | 112 tests: language + app/EXE builder + parity + PyHope + workspace + Playground + arcade |
Community
GitHub Issues News - Events + EventsSuccess Stories
diff --git a/editors/vscode/snippets/pyv2.json b/editors/vscode/snippets/pyv2.json index 1fba756..0120775 100644 --- a/editors/vscode/snippets/pyv2.json +++ b/editors/vscode/snippets/pyv2.json @@ -55,6 +55,30 @@ ], "description": "For loop over a range" }, + "try-catch": { + "prefix": "trycatch", + "body": [ + "try:", + " ${1:work}", + "catch ${2:error}:", + " ${3:print(error.kind, error.message)}", + "end" + ], + "description": "Recover from a runtime error" + }, + "try-catch-finally": { + "prefix": "tryfinal", + "body": [ + "try:", + " ${1:work}", + "catch ${2:error}:", + " ${3:recovery}", + "finally:", + " ${4:cleanup}", + "end" + ], + "description": "Recover from an error and always clean up" + }, "f-string": { "prefix": "fstr", "body": "f\"${1:text} {${2:expr}}\"", diff --git a/editors/vscode/syntaxes/pyv2.tmLanguage.json b/editors/vscode/syntaxes/pyv2.tmLanguage.json index b0410c6..71c5718 100644 --- a/editors/vscode/syntaxes/pyv2.tmLanguage.json +++ b/editors/vscode/syntaxes/pyv2.tmLanguage.json @@ -112,7 +112,7 @@ "patterns": [ { "name": "keyword.control.pyv2", - "match": "\\b(if|elif|else|while|for|in|return|break|continue)\\b" + "match": "\\b(if|elif|else|while|for|in|return|raise|try|catch|finally|break|continue)\\b" }, { "name": "storage.type.function.pyv2", diff --git a/examples/error_recovery.pyv2 b/examples/error_recovery.pyv2 new file mode 100644 index 0000000..9119b2e --- /dev/null +++ b/examples/error_recovery.pyv2 @@ -0,0 +1,27 @@ +# error_recovery.pyv2 — structured failures without exception classes + +fn parse_port(raw): + if raw == "": + raise {kind: "ConfigError", message: "port is required"} + end + port = int(raw) + if port < 1 or port > 65535: + raise {kind: "ConfigError", message: "port must be between 1 and 65535"} + end + return port +end + +inputs = ["8080", "", "70000", "not-a-number"] +for raw in inputs: + try: + port = parse_port(raw) + print("ready:", port) + catch error: + print(error.kind + ":", error.message, "at line", error.line) + finally: + print("checked", repr(raw)) + end +end + +print("numbered inputs:", enumerate(inputs, 1)) +print("numeric total:", sum([8000, 80])) diff --git a/games.html b/games.html index 4da5bee..2ad2199 100644 --- a/games.html +++ b/games.html @@ -9,6 +9,7 @@ + Skip to contentHelp @CubeCometYT reach 1K
Subscribe on YouTube -50 things worth knowing
closures, editor setup, CC0 sprites, DDA ray casting and a 9.4-million-pixel GPU frame.push and pop
Slices
slice(start, end) makes a new string or list and supports negative positions.
print([0, 1, 2, 3].slice(1, 3))
-Sorting lists
-sort returns a new list, while sort_by accepts a key function.
-print([3, 1, 2].sort())
+ Iterable toolkit
+Sort, total, number, pair, or truth-test iterable values with concise builtins.
+print([3, 1, 2].sort())
+print(sum(range(5)))
+print(enumerate(["a", "b"], 1))
+print(zip([1, 2], ["a", "b"]))
Conversions
Assertions
assert is a normal function and accepts your own message.
assert(len([1, 2]) == 2, "list size changed")
-Read errors
-Errors include a kind, message, source line, and function stack frames.
-fn boom(): return missing end
-boom()
+ Recover from errors
+Catch runtime failures as maps with kind, message, line, and trace; finally always runs.
+try: raise "stop"
+catch error: print(error.kind, error.message)
+finally: print("clean")
+end
All the Flow You'd Expect
»»> Learn More + +Get Started
+Whether you're new to programming or shipping your next app, start with a short guided path.
+ Start the tutorial › +Download
+Install the Sudbury language, desktop workspace, PyHope, and Windows EXE toolchain together.
+ Download Python v2 › +Documentation
+Browse the language reference, editor setup, application APIs, and packaging guides.
+ Read the docs › +Try Python v2
+Run the real browser interpreter, inspect errors, build a website, or switch to Classic mode.
+ Open Playground › +Donations are coming soon
- Our own desktop Launcher, offline website builder, PyHope, - sprite games, installers, free assets, and a 9M GPU lab. + Now with structured
try/catch/finally,
+ richer iterable tools, the desktop Launcher, Windows EXE builds, PyHope, and the 9M GPU lab.
Donations are coming soon
»»>Success Stories
Things people have built with Python v2 + PyHope — from a pure CPU framebuffer to an optional 9.4-million-pixel GPU render.
+“One readable language can move from a browser idea to a desktop workspace, + a game, a polished website, and a real Windows application.”+
»»>Why v2 beats v1
"n=" + str(n)"n=" + nx if ok else y (backwards)ok ? x : ycatch error gives a useful map; finally always runsassert statementassert(cond, msg) — a normal functionnonlocal rulesF-Strings, Solved Forever
expressions and all. String concatenation with numbers is legal too.Forward Ternary
-ok ? "yes" : "no" reads left to right, like your eyes do.
- Wild concept.
Errors You Can Work With
+Recover with try, inspect error.kind and
+ error.message, and rely on finally for cleanup.
ternary
Condition first, like a question should be.
status = ok ? "yes" : "no"
try / catch / finally
+Recover from runtime errors, inspect their fields, and always clean up.
+try: risky() catch error: print(error.kind) end
+ builtins
-len, range, type, str,
- int, sort, join, assert, …
print(type(2), len("abc"))
+ len, range, sum, enumerate,
+ zip, all, any, type, …
print(sum(range(5)))
string methods
@@ -373,32 +418,57 @@numbers
»»>News & Events
-Python v2 1.1 "Sudbury" released
-Python v2 gets its own desktop Launcher, portfolio builder, and - Windows EXE toolchain—plus safe app APIs, PyHope, and a 9M GPU lab.
- Read more → -Portfolio Studio lands in Playground
-Edit a Python v2 starter and watch it become a responsive personal, - project, and game showcase. Preview the page or inspect its HTML.
- Open the studio → -Pyv2Conf 2027 — call for talks
-One track, one rule: every talk must demo something running in - the CPU renderer. Stickers included.
- Read more → -»»>Latest News
+ All news +-
+
-
+
+ Structured error recovery lands in both runtimes ++
Use
try,catch,finally, andraisewith inspectable error details.
+ -
+
+ Python v2 1.1 “Sudbury” released ++
The desktop Launcher and reproducible Windows EXE workflow are available now.
+ -
+
+ Portfolio Studio arrives in Playground ++
Edit Python v2 data and preview a responsive personal site with its exact HTML.
+
»»>Upcoming
+ Community +-
+
-
+
+ Complete Python v2 installation video ++
The full language, editor, PyHope, and app-building walkthrough unlocks at 1,000 subscribers.
+ -
+
+ Donation support opens ++
Donation support is not open yet; no payment information is being collected.
+ -
+
+ Browser build session ++
Open the Playground and make a language program, game data set, or portfolio site.
+
»»>The Community Runs On Snacks
Games & PyHope
diff --git a/main.js b/main.js index 7fe9d2c..8cc0278 100644 --- a/main.js +++ b/main.js @@ -13,7 +13,7 @@ "(#[^\\n]*)", // comment "(f?\"(?:\\\\.|[^\"\\\\\\n])*\"|f?'(?:\\\\.|[^'\\\\\\n])*')", // strings / f-strings "\\b(\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?)\\b", // numbers - "\\b(fn|if|elif|else|while|for|in|return|break|continue|and|or|not|true|false|nil|end)\\b", + "\\b(fn|if|elif|else|while|for|in|return|raise|try|catch|finally|break|continue|and|or|not|true|false|nil|end)\\b", "([+\\-*/%<>=!]+|[()\\[\\]{},.:?])", // operators / punctuation ].join("|"), "g" @@ -120,22 +120,21 @@ print("best:", hero.scores[-1]) print("city:", hero.get("city", "unknown"))`, }, { - title: "Recursion Without Regret", - desc: "First-class functions, real closures, and a ternary that reads the way " + - "you think:ok ? \"yes\" : \"no\". The classics, fixed.",
- link: "More language tools",
- href: "docs.html",
+ title: "Errors You Can Actually Handle",
+ desc: "Recover with try and catch, inspect a plain error " +
+ "map, and use finally for cleanup that always runs. Raise your " +
+ "own named errors without writing a class.",
+ link: "Learn structured recovery",
+ href: "docs.html#language",
code:
-`fn fib(n):
- if n < 2:
- return n
- end
- return fib(n - 1) + fib(n - 2)
-end
-
-for i in range(10):
- label = i % 2 == 0 ? "even" : "odd"
- print(f"fib({i}) = {fib(i)} ({label})")
+`try:
+ print("loading settings…")
+ raise {kind: "ConfigError", message: "port is required"}
+catch error:
+ print(error.kind + ":", error.message)
+ print("source line:", error.line)
+finally:
+ print("settings check complete")
end`,
},
];
diff --git a/playground.html b/playground.html
index 1b0cf92..fb39209 100644
--- a/playground.html
+++ b/playground.html
@@ -10,6 +10,7 @@
+ Skip to content
-