throw(n)

πŸ“¦
version 9.0.3 Β· 2 versions
  • 9.0.3 Β· alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0 (latest)
  • 8.6.10 Β· centos-stream 9
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0

πŸ’– throw(n) β€” bestie's guide to yeeting a machine-readable error πŸ’–

okay so real quick: this is a page from the Tcl Built-In Commands manual, and the command is literally called throw. yes. we're throwing. we're not being normal about it. 🌈


✨ NAME ✨

throw β€” Generate a machine-readable error 🫢


πŸŽ€ SYNOPSIS πŸŽ€

throw type message

two args. that's the whole thing. slay.


πŸ’… DESCRIPTION πŸ’…

okay so what this command does is cause the current evaluation to be unwound with an error. like, it's giving "nope, we're done here" energy, and it does it right now, no waiting. ✨

the error it creates is fully described by the type and message arguments:

  • type β€” must contain a list of words describing the error, and it has to be in a form that's machine-readable. this list also forms the error-code part of the result dictionary. so it's the nerdy structured part, iykyk.
  • message β€” should contain text that is intended for display to a human being. yes bestie, actual words, for actual eyes. 😭

now, the drama: the stack will be unwound until the error gets trapped by a suitable catch or try command. that's the happy ending.

but if it never gets trapped? if it just sails all the way to the event loop? then it gets reported through the bgerror mechanism. periodt.

and if it reaches the top level of script evaluation in tclsh, it will be printed on the console, and then β€” in the non-interactive case β€” it causes an exit. πŸ’€ (the behavior in other programs will depend on the details of how Tcl is embedded and used, so like... it varies, ngl.)

one more vibe rule: by convention, the words in the type argument should go from most general to most specific. general first, then you zoom in. iconic.


🌸 EXAMPLES 🌸

the following produces an error that is identical to the one produced by expr when it tries to divide a value by zero. so like, if you ever wanted to cosplay as expr, here's your moment:

throw {ARITH DIVZERO {divide by zero}} {divide by zero}

πŸ¦‹ SEE ALSO πŸ¦‹


⭐ KEYWORDS ⭐

error, exception


and that's the page, bestie!! πŸ“ this whole thing came from the Tcl crew, version 8.6, filed under throw(n) β€” go forth and throw responsibly (or don't, it's giving chaos and honestly? valid) πŸ’œπŸ§š

πŸ“¦ where this page comes from