Artifact 6d5b355cd7dbb4ca6c82551d2d59d58423ec8d517a06aac365a9a7cea4715a17:
- File doc/markdown/throw.md — part of check-in [bb08aafe0a] at 2025-07-15 19:41:45 on branch tip-700 — some non-change cosmetics to make the ctags implementation in Geany 2.1 partly happy again (user: Torsten, size: 1576) [annotate] [blame] [check-ins using]
CommandName: throw ManualSection: n Version: 8.6 TclPart: Tcl TclDescription: Tcl Built-In Commands Links:
- catch(n)
- error(n)
- errorCode(n)
- errorInfo(n)
- return(n)
- try(n) Keywords:
- error
- exception Copyright:
- Copyright (c) 2008 Donal K. Fellows ---
Name
throw - Generate a machine-readable error
Synopsis
::: {.synopsis} ::: [throw]{.cmd} [type]{.arg} [message]{.arg} :::
Description
This command causes the current evaluation to be unwound with an error. The error created is described by the fItypefR and fImessagefR arguments: fItypefR 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), and fImessagefR should contain text that is intended for display to a human being.
The stack will be unwound until the error is trapped by a suitable fBcatchfR or fBtryfR command. If it reaches the event loop without being trapped, it will be reported through the fBbgerrorfR mechanism. If it reaches the top level of script evaluation in fBtclshfR, it will be printed on the console before, in the non-interactive case, causing an exit (the behavior in other programs will depend on the details of how Tcl is embedded and used).
By convention, the words in the fItypefR argument should go from most general to most specific.
Examples
The following produces an error that is identical to that produced by fBexprfR when trying to divide a value by zero.
throw {ARITH DIVZERO {divide by zero}} {divide by zero}