throw(3tcl)
π₯ throw β generate a machine-readable error π₯
okay bestie, buckle up, we're in the throw page of the Tcl Built-In Commands manual and honestly? this one is a whole mood. it's giving "i am going to ruin this evaluation's entire day, on purpose, with structure." π
β¨ SYNOPSIS β¨
throw type message
two args. that's it. that's the whole vibe. π
π¦ DESCRIPTION π¦
so like, this command causes the current evaluation to be unwound with an error. fr fr, you're not asking nicely β you're throwing. π
the error that gets created is described by the type and message arguments, and no cap, these two are doing very different jobs:
typeβ this one must contain a list of words describing the error, in a form that is machine-readable (and which will form the error-code part of the result dictionary). so it's the nerdy one. it's the one the computer reads. π€messageβ this one should contain text that is intended for display to a human being. so it's the pretty one. it's the one your friend reads at 2am and goes "oh no bestie". π
then the stack gets unwound until the error is trapped by a suitable catch or try command. like, somebody's gotta catch it, or it just keeps going. π
and if nobody catches it:
- if it reaches the event loop without being trapped, it will be reported through the
bgerrormechanism. π£ - if it reaches the top level of script evaluation in
tclsh, it will be printed on the console before, in the non-interactive case, causing an exit πͺ β and just so you know, the behavior in other programs will depend on the details of how Tcl is embedded and used. so like, ymmv, it depends on the embedding. π
also, by convention, the words in the type argument should go from most general to most specific. so like, big category first, tiny detail last. general β specific, periodt. π
πΈ EXAMPLES πΈ
the following produces an error that is identical to that produced by expr when trying to divide a value by zero. iconic behavior, honestly:
throw {ARITH DIVZERO {divide by zero}} {divide by zero}
see how the type is the general-to-specific list and the message is the human-readable bit? that's the whole pattern. slay. β¨
π SEE ALSO π
π KEYWORDS π
error, exception
and that's the page, bestie π«Ά this was Tcl 8.6, the throw(3tcl) manual page β go forth and throw responsibly, mwah ππΈπ¦
π¦ where this page comes from
- debian bookworm: tcl8.6-doc 8.6.13+dfsg-2
- debian trixie: tcl8.6-doc 8.6.16+dfsg-1
- debian trixie: tcl9.0-doc 9.0.1+dfsg-2
- ubuntu jammy: tcl8.6-doc 8.6.12+dfsg-1build1
- ubuntu noble: tcl8.6-doc 8.6.14+dfsg-1build1
- ubuntu questing: tcl8.6-doc 8.6.17+dfsg-1
- ubuntu questing: tcl9.0-doc 9.0.2+dfsg-1
- ubuntu resolute: tcl8.6-doc 8.6.17+dfsg-1build1
- ubuntu resolute: tcl9.0-doc 9.0.3+dfsg-1
- ubuntu stonking: tcl8.6-doc 8.6.18+dfsg-1
- ubuntu stonking: tcl9.0-doc 9.0.4+dfsg-1
- 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