throw(n)
π 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
- alpine 3.22: tcl-doc 8.6.16-r0 Β· TCL
- alpine 3.23: tcl-doc 8.6.17-r0 Β· TCL
- alpine 3.23: tcl9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tcl-doc 8.6.17-r1 Β· TCL
- alpine 3.24: tcl9-doc 9.0.3-r2 Β· TCL
- arch rolling: tcl 8.6.16-1 Β· TCL
- centos-stream 10: tcl-doc 1:8.6.13-4.el10 Β· TCL AND GPL-3.0-or-later WITH bison-exception-2.2 AND BSD-3-Clause
- fedora 43: tcl-doc 1:9.0.2-1.fc43 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- fedora 44: tcl-doc 1:9.0.2-1.fc44 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- nixos 26.05: tcl 9.0.3
- nixpkgs unstable: tcl 9.1.0
- opensuse-leap 16.0: tcl 8.6.15-160000.2.2 Β· TCL
- opensuse-leap 16.0: tcl 8.6.15-160000.2.2 Β· TCL
- opensuse-leap 16.0: tcl 8.6.15-160000.2.2 Β· TCL
- opensuse-leap 16.0: tcl 8.6.15-160000.2.2 Β· TCL
- Copyright (c) 2008 Donal K. Fellows
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms