fluffos/docs/efun
gesslar e059c891cb
docs: document the real rules for throw(), add a structured catch() example (#1335)
* docs: document the real rules for throw(), add a structured catch() example

throw.md called throw() "forces an error to occur in an object" and
treated the catch() requirement as a style suggestion. Neither matches
what f_throw()/throw_error() do. Rewrite the page around the rules the
driver actually implements, each verified against a running driver:

- An uncaught throw() raises *Throw with no catch. and discards the
  value. This is a requirement, not advice.
- Any type round-trips through catch() verbatim, not just strings.
- throw(0) is indistinguishable from success, since catch() returns 0
  for "no error". This was documented only on catch.md.
- A thrown value skips the error machinery entirely: no traceback, no
  debug log, no error_handler() apply, and no leading '*'. That '*' is
  the discriminator handling code keys on, and it appeared on neither
  page.
- Only the innermost catch() sees it; rethrow to propagate further.
- It crosses ordinary calls (call_other, inherited functions,
  evaluate(), filter/sort_array callbacks, a create() running under
  load_object) but cannot escape a call the driver starts itself
  (call_out, input_to, driver applies), which each begin a fresh chain
  with no catch above them.

The old example's `return;` after throw() was unreachable, and it
concatenated a caught driver error into a new message, burying the '*'
mid-string so callers testing err[0] would stop recognising it. Both
fixed.

catch.md gains a third example that throws a class: its existing two
both use string errors and imply catch() only ever yields text. Written
with dot accessors and named-argument new(), matching the ordering in
lpc/types/classes.md.

Chinese translations updated to match. The zh-CN catch.md description
said throw() returns a non-zero value, narrower than "any value except
0" and the exact claim the new example rests on; corrected.

Every example block was extracted from the markdown and compiled by the
driver, Chinese comments and strings included. Both locales build clean.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014JuB4acdTho1rmAL7PwvS1

* docs: fix the rethrow example forging a driver-error '*'

Review feedback on the rethrow example was right, and the bug is worse
than a style nit: the example contradicted the rule its own page
teaches. It stripped a leading '*' from the caught value and then
unconditionally put one back, so anything that was not a driver error
came back disguised as one. Verified against the driver:

  mudlib string -> "*move_or_fail(): took too long\n"   (forged '*')
  structured    -> "*Bad type argument to +. Had string and array\n"

The second case is worse still: concatenating a string onto a thrown
array destroys the original failure and replaces it with a type error
raised inside the handler.

Re-add the '*' only when it was there to begin with, add context
without it for a non-driver string, and pass a non-string value through
untouched. Now:

  driver error  -> "*move_or_fail(): bad thing\n"
  mudlib string -> "move_or_fail(): took too long\n"
  structured    -> ({ "insufficient_funds", 7 })

Also quote the uncaught-throw error as the full string it actually is,
"*Throw with no catch.\n", matching the two example strings shown a few
lines above that spell out their trailing newline.

And drop the "any value, except 0" phrasing on catch.md, which reads as
though throwing 0 were rejected. It is not rejected, merely undetectable,
since catch() already returns 0 for "no error". The zh-CN page inherited
the same ambiguity from the English; both now say so explicitly.

All four example blocks recompiled from the markdown; both locales build
clean.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014JuB4acdTho1rmAL7PwvS1

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-28 16:08:29 -07:00
..
arrays docs: document that shuffle() reorders its argument array in place (#1332) 2026-07-27 18:56:08 -07:00
async docs: fully-expandable generated sidebar + Chinese docs via Docusaurus i18n (#1246) 2026-07-11 17:20:25 -04:00
buffers vm: string foreach/ref fixes, buffers as byte arrays (foreach, strict bytes, to_buffer), thorough ref tests; #1196 docs follow-up (#1250) 2026-07-12 01:39:30 -04:00
calls docs: document the real rules for throw(), add a structured catch() example (#1335) 2026-07-28 16:08:29 -07:00
contrib reference loops: docs, runtime cycle efuns, orphan collector, copy() unwind fix (#1276) 2026-07-16 00:06:37 -07:00
crypto docs: fully-expandable generated sidebar + Chinese docs via Docusaurus i18n (#1246) 2026-07-11 17:20:25 -04:00
db docs: fully-expandable generated sidebar + Chinese docs via Docusaurus i18n (#1246) 2026-07-11 17:20:25 -04:00
ed docs: document the third argument (scroll_lines) of ed_start() (#1328) 2026-07-27 15:05:26 -07:00
external docs: fully-expandable generated sidebar + Chinese docs via Docusaurus i18n (#1246) 2026-07-11 17:20:25 -04:00
ffi docs: rewrite FFI reference around buffer features, add worked libc examples (#1275) 2026-07-15 22:09:25 -07:00
filesystem docs: fully-expandable generated sidebar + Chinese docs via Docusaurus i18n (#1246) 2026-07-11 17:20:25 -04:00
floats docs: validate "See Also" references, drop dead ones, document valid_ffi (#1251) 2026-07-12 01:09:17 -04:00
functions docs: validate "See Also" references, drop dead ones, document valid_ffi (#1251) 2026-07-12 01:09:17 -04:00
general docs: validate "See Also" references, drop dead ones, document valid_ffi (#1251) 2026-07-12 01:09:17 -04:00
interactive docs: flesh out 31 TBW efun reference pages (#1248) 2026-07-11 22:07:47 -04:00
internals docs: document dual (expr)/{ block } syntax for catch and time_expression (#1278) 2026-07-17 11:56:22 -07:00
jsbridge docs: fully-expandable generated sidebar + Chinese docs via Docusaurus i18n (#1246) 2026-07-11 17:20:25 -04:00
mappings docs: validate "See Also" references, drop dead ones, document valid_ffi (#1251) 2026-07-12 01:09:17 -04:00
mudlib docs: fully-expandable generated sidebar + Chinese docs via Docusaurus i18n (#1246) 2026-07-11 17:20:25 -04:00
numbers docs: validate "See Also" references, drop dead ones, document valid_ffi (#1251) 2026-07-12 01:09:17 -04:00
objects docs: validate "See Also" references, drop dead ones, document valid_ffi (#1251) 2026-07-12 01:09:17 -04:00
parsing docs: fully-expandable generated sidebar + Chinese docs via Docusaurus i18n (#1246) 2026-07-11 17:20:25 -04:00
pcre docs: fully-expandable generated sidebar + Chinese docs via Docusaurus i18n (#1246) 2026-07-11 17:20:25 -04:00
sockets docs: fully-expandable generated sidebar + Chinese docs via Docusaurus i18n (#1246) 2026-07-11 17:20:25 -04:00
strings docs: validate "See Also" references, drop dead ones, document valid_ffi (#1251) 2026-07-12 01:09:17 -04:00
system docs: document the third argument (flag) of function_exists() (#1326) 2026-07-27 18:56:30 -07:00