Error processing request

Parameters

CONTENT_LENGTH0
REQUEST_METHODGET
REQUEST_URI/revision/catch?V=44
QUERY_STRINGV=44
CONTENT_TYPE
DOCUMENT_URI/revision/catch
DOCUMENT_ROOT/var/www/nikit/nikit/nginx/../docroot
SCGI1
SERVER_PROTOCOLHTTP/1.1
HTTPSon
REMOTE_ADDR172.70.174.138
REMOTE_PORT43008
SERVER_PORT4443
SERVER_NAMEwiki.tcl-lang.org
HTTP_HOSTwiki.tcl-lang.org
HTTP_CONNECTIONKeep-Alive
HTTP_ACCEPT_ENCODINGgzip
HTTP_X_FORWARDED_FOR44.192.114.32
HTTP_CF_RAY7252d3efbab88232-IAD
HTTP_X_FORWARDED_PROTOhttps
HTTP_CF_VISITOR{"scheme":"https"}
HTTP_USER_AGENTCCBot/2.0 (https://commoncrawl.org/faq/)
HTTP_ACCEPTtext/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_ACCEPT_LANGUAGEen-US,en;q=0.5
HTTP_CF_CONNECTING_IP44.192.114.32
HTTP_CF_IPCOUNTRYUS
HTTP_CDN_LOOPcloudflare

Body


Error

Unknow state transition: LINE -> END

-code

1

-level

0

-errorstack

INNER {returnImm {Unknow state transition: LINE -> END} {}} CALL {my render_wikit catch ***COMMAND***\ncatch\ -\ Evaluate\ script\ and\ trap\ exceptional\ returns\ \n\n***USAGE***\n'''catch'''\ ''script''\ ?''messageVarName''?\ ?''optionsVarName''?\n**\ Synopsis\ **\n***CONTEXT***\nTCL\ core\ command\n\ \n***DESCRIPTION***\nThe\ '''catch'''\ command\ may\ be\ used\ to\ prevent\ errors\ from\ aborting\ command\ interpretation.\ \ '''Catch'''\ calls\ the\ Tcl\ interpreter\ recursively\ to\ execute\ ''script'',\ and\ always\ returns\ without\ raising\ an\ error,\ regardless\ of\ any\ errors\ that\ might\ occur\ while\ executing\ script.\n'''`catch`'''\ ''`script`''\ ?''`messageVarName`''?\ ?''`optionsVarName`''?\nIf\ ''script''\ raises\ an\ error,\ '''catch'''\ will\ return\ a\ non-zero\ integer\ value\ corresponding\ to\ one\ of\ the\ exceptional\ return\ codes\ (see\ tcl.h\ for\ the\ definitions\ of\ code\ values).\ \ If\ the\ ''messageVarName''\ argument\ is\ given,\ then\ the\ variable\ it\ names\ is\ set\ to\ the\ error\ message\ from\ interpreting\ script.\ If\ ''optionsVarName''\ is\ given,\ then\ the\ variable\ it\ names\ is\ set\ to\ a\ \[dict\]ionary\ describing\ details\ of\ the\ exceptional\ situation.\n\nIf\ ''script''\ does\ not\ raise\ an\ error,\ catch\ will\ return\ '''0'''\ (TCL_OK)\ and\ set\ the\ variable\ to\ the\ value\ returned\ from\ script.\n\nNote\ that\ '''catch'''\ catches\ all\ exceptions,\ including\ those\ generated\ by\ '''\[break\]'''\ and\ '''\[continue\]''',\ ''and\ '''\[return\]''''',\ as\ well\ as\ errors.\ The\ only\ errors\ that\ are\ not\ caught\ are\ syntax\ errors\ found\ when\ the\ script\ is\ compiled.\ \ This\ is\ because\ the\ catch\ command\ only\ catches\ errors\ during\ runtime.\ \ When\ the\ catch\ statement\ is\ compiled,\ the\ script\ is\ compiled\ as\ well\ and\ any\ syntax\ errors\ will\ generate\ a\ Tcl\ error.\ \ \ \n\ \n***MAN\ PAGE***\nhttp://www.tcl.tk/man/tcl8.5/TclCmd/catch.htm\n\ \n***SEE\ ALSO***\n\[break\],\ \[continue\],\ \[return\],\ \[error\],\ \[errorCode\],\ \[errorInfo\],\ \[try\]\n**\ Documentation\ **\n***EXAMPLES***\nThe\ '''catch'''\ command\ may\ be\ used\ in\ an\ '''\[if\]'''\ to\ branch\ based\ on\ the\ success\ of\ a\ script.\ \ \nif\ \{\[catch\ \{open\ \$someFile\ w\}\ fid\]\}\ \{\n\ if\ \{\ \[catch\ \{open\ \$someFile\ w\}\ fid\]\ \}\ \{\n\ \ \ puts\ stderr\ \"Could\ not\ open\ \$someFile\ for\ writing\\n\$fid\"\n\ \ \ exit\ 1\n\ \}\n\n<<discussion>>\n\nThe\ '''catch'''\ command\ will\ not\ catch\ compiled\ syntax\ errors.\ \ The\ first\ time\ proc\ '''foo'''\ is\ called,\ the\ body\ will\ be\ compiled\ and\ a\ Tcl\ error\ will\ be\ generated.\ \ \ \n\n======\n%\ proc\ foo\ \{\}\ \{\n\ \ \ catch\ \{expr\ \{1\ +-\ \}\}\n\ \}\n\n%\ set\ a\ \[foo\]\n1\n======\n\nWhen\ foo\ is\ executed,\ \n(from:\ Tcl\ Help\;\ bold\ words\ added\ by\ \[RS\])\n\n\[DKF\]:\ Actually,\ it's\ catching\ the\ syntax\ error\ just\ fine\;\ that\ it\ didn't\ used\ to\ was\ a\ bug\ in\ earlier\ versions\ of\ the\ bytecode\ compiler,\ and\ that\ was\ fixed\ in\ around\ the\ 8.4\ timeframe.\n\n----\n***Catching\ large\ chunks\ of\ code***\n\n\nWhy\ is\ it\ a\ bad\ idea\ to\ \"catch\"\ large\ chunks\ of\ code?\ Because\ Tcl\ stops\ execution\ of\ the\ code\ as\ soon\ as\ it\ encounters\ an\ error.\ This\ behavior\ can\ lead\ to\ problems\ like\ this:\n\n======\n\ \ \ \ #\ I've\ got\ an\ open\ socket\ whose\ handle's\ stored\ in\ fid\n\ \ \ \ catch\ \{\n\ \ \ \ \ \ \ \ puts\ \$fid\ \"Here's\ my\ last\ message.\"\n\ \ \ \ \ \ \ \ close\ \$fid\n\ \ \ \ \}\ err\nIf\ the\ \"puts\"\ command\ generates\ an\ error,\ \"catch\"\ detects\ that\ and\ stops\ execution\ of\ the\ code\ block.\ You\ never\ get\ around\ to\ closing\ the\ channel.\ It's\ better\ practice\ to\ put\ separate\ \"catch\"\ commands\ around\nboth\ the\ \"puts\"\ and\ the\ \"close\"\ commands\ to\ detect\ errors\ in\ either\ case\ and\ handle\ them\ appropriately.\n\nThis\ is\ a\ different\ style\ of\ programming\ than\ in\ a\ language\ like\ Java.\ In\ Java,\ you\ can\ have\ a\ variety\ of\ exceptions,\ each\ represented\ by\ a\ different\ class,\ that\ signal\ different\ types\ of\ error\ conditions.\ Then\nin\ a\ \"try\"\ block,\ you\ can\ test\ for\ the\ different\ types\ of\ error\ conditions\ separately\ and\ handle\ them\ in\ different\ ways.\ (My\ complaint\ about\ Java\ is\ that\ there\ seems\ to\ be\ so\ many\ different\ classes,\ I'm\ often\ at\ a\ loss\ as\ to\ which\ ones\ I\ should\ be\ testing\ for.)\ In\ contrast,\ Tcl\ generally\ has\ only\ one\ type\ of\ error.\ In\ theory,\ we\ could\ use\ different\ return\ codes\ to\ signal\ different\ types\ of\ error,\ but\ in\ practice\ this\ is\ hardly\ ever\ used.\n\n----\n\nI\ think\ it\ is\ extreme\ parochialism\ to\ state\ \"it's\ a\ bad\ idea\ to\ code\ this/that\ way\".\ \ It\ is\ perfectly\ reasonable\ to\ catch\ \"large\"\ chunks:\n\n======\n\ \ if\ \{\ \[\ catch\ \{\n\ \ \ \ close\ \$fid\n\}\ err\ \]\ \}\ \{\n\ \}\ err\ \]\ \}\ \{\n\ \ \ \ return\ -code\ error\ \$err\n\}\n\ \}\nIf\ you\ catch\ \"large\"\ chunks\ you\ can\ at\ least\ have\ a\ program\ that\ can\ tolerate\ some\ errors\ that\ you\ did\ not\ anticipate.\ It\ is\ certainly\ better\ to\ fix\ problems\ the\ first\ time\ they\ appear,\ but\ tinkering\ with\ the\ code\ on\ a\ live\ system\ is\ rather\ poor\ practice.\n\nMost\ users\ would\ rather\ ''not''\ have\ the\ software\ come\ to\ a\ screeching\ halt\ on\ every\ unanticipated\ error.\ \ -'''PSE'''\n\n\n----\n\n\n======\nset\ resource\ \[some\ allocator\]\nif\ \{\[set\ result\ \[catch\ \{some\ code\ with\ \$resource\}\ resulttext\]\]\}\ \{\n\ \ \ \ #\ remember\ global\ error\ state,\ as\ de-allocation\ may\ overwrite\ it\n\ \ \ \ set\ einfo\ \$::errorInfo\n\ \ \ \ set\ ecode\ \$::errorCode\n\n\ \ \ \ #\ free\ the\ resource,\ ignore\ nested\ errors\n\ \ \ \ catch\ \{deallocate\ \$resource\}\n\n\ \ \ \ #\ report\ the\ error\ with\ original\ details\n\ \ \ \ return\ -code\ \$result\ \\\n\ \ \ \ \ \ \ \ \ \ \ -errorcode\ \$ecode\ \\\n\ \ \ \ \ \ \ \ \ \ \ -errorinfo\ \$einfo\ \\\n\ \ \ \ \ \ \ \ \ \ \ \$resulttext\n\}\ndeallocate\ \$resource\n\ncontinue\ normally\n======\n\nBesides\ a\ full-scale\ Java-style\ `\[try\]`\ implementation\ with\ all\ kinds\ of\ functionality\ for\ the\ catch\ branches,\ this\ could\ probably\ also\ be\ improved\ with\ a\ simpler\ command\ ''withresource'',\ that\ doesn't\ have\ the\ catch\ branch\ functionality,\ like\ this:\nBesides\ a\ full-scale\ Java-style\ \[try\]\ implementation\ with\ all\ kinds\ of\ functionality\ for\ the\ catch\ branches,\ this\ could\ probably\ also\ be\ improved\ with\ a\ simpler\ command\ ''withresource'',\ that\ doesn't\ have\ the\ catch\ branch\ functionality,\ like\ this:\n======\n\ set\ resource\ \[some\ allocator\]\n\ withresource\ \{\n\ \ \ \ \ some\ code\ with\ \$resource\n\ \}\ finally\ \{\n\ \ \ \ \ #\ this\ would\ be\ executed\ always,\ even\ in\ case\ of\ error\n\ \ \ \ \ deallocate\ \$resource\n\ \}\ncontinue\ normally\n\ continue\ normally\n\[HaO\]\ 2012-02-17:\ Within\ the\ upper\ code,\ one\ may\ use\ the\ tcl\ 8.5\ feature\ of\ an\ option\ dict\ returned\ by\ catch.\n\[HaO\]\ within\ the\ upper\ code,\ one\ may\ use\ the\ tcl\ 8.5\ feature\ of\ an\ option\ dict\ returned\ by\ catch.\nHere\ is\ the\ modified\ code\ which\ does\ the\ same:\n\nset\ resource\ \[some\ allocator\]\nif\ \{\[set\ result\ \[catch\ \{some\ code\ with\ \$resource\}\ resulttext\ resultoptions\]\]\}\ \{\n\ \ \ \ #\ free\ the\ resource,\ ignore\ nested\ errors\n\n\ \ \ \ catch\ \{deallocate\ \$resource\}\n\ \ \ \ \n\ \ \ \ #\ report\ the\ error\ with\ original\ details\n\ \ \ \ dict\ unset\ resultoptions\ -level\n\ \ \ \ return\ -options\ \$resultoptions\ \$resulttext\n\ \ \ \ return\ -options\ \$resultoptions\ndeallocate\ \$resource\n\ncontinue\ normally\n======\n\n2015-12-07:\ \[heinrichmartin\]\ proposed\ on\ clt\ to\ use\ `\[dict\ incr\]\ resultoptions\ -level`\ instead\ of\ `\[dict\ unset\]\ resultoptions\ -level`.\ \ Results\ in\ the\ same\ but\ might\ be\ more\ straightforward.\n----\n***Old\ catch\ bug\ discussed***\n\n\[MS\]:\ ''Oops,\ forgot\ to\ mention\ it\ here:\ this\ bug\ was\ closed\ on\ 2000-10-25,\ it\ is\ fixed\ in\ tcl8.4a4.''\n\nNote\ that\ the\ bytecode\ compiling\ of\ \[\[catch\]\]\ in\ Tcl\ 8.x\ has\ a\ bug.\ '''\[catch\]'''\ will\ inappropriately\ catch\ errors\ in\ the\ substitution\ of\ its\ arguments:\n\n\ %\ #\ should\ return\ 'foo'\n\ %\ catch\ \[error\ foo\]\n\ 1\n\nCompare\ with\ Tcl\ 7.6:\n\n\ %\ catch\ \[error\ foo\]\n\ foo\n\nTo\ work\ around\ the\ bug,\ defeat\ the\ bytecode\ compiler\ by\ generating\ '''\[catch\]''':\n\n\ %\ \[format\ catch\]\ \[error\ foo\]\n\ foo\n\nTrack\ Sourceforge\ bug\ #\ 119184\ to\ learn\ if/when\ this\ bug\ is\ fixed.\nhttp://sourceforge.net/bugs/?func=detailbug&bug_id=119184&group_id=10894\n\n'''DGP'''\n\n----\n***Catch\ return\ example***\n\nExample\ for\ caught\ return,\ from\ a\ posting\ of\ \[George\ Petasis\]\ in\ \[the\ comp.lang.tcl\ newsgroup\]:\n======\n\ %\ proc\ foo\ \{\}\ \{\n\ \ \ \ \ \ \ \ puts\ \"catch\ result\ is\ :\[catch\ \{\ return\}\]\"\n\ \ \ \ \ \ \ \ puts\ \"after\ return\"\n\ \}\ \n\ %\ foo\n\ catch\ result\ is\ :2\n\ after\ return\ \n\n----\n***Catching\ break,\ continue,\ error,\ and\ return***\n\nFor\ a\ more\ complex\ worked\ example\ of\ catching\ \[\[break\]\],\ \[\[continue\]\],\ \[\[error\]\]\ and\ \[\[return\]\],\ this\ Wiki\ has\ a\ pure\ Tcl\ implementation\ of\ a\ Java-style\ \[try\ ...\ finally\ ...\]\ construct.\ \ --\ \[KBK\]\ 24\ Dec\ 2000\n**\ `\[catch\]`\ and\ `\[exec\]`\ **\n----\nThe\ options\ dictionary\ from\ catching\ a\ call\ to\ `\[exec\]`\ contains\ a\ wealth\ of\nWhen\ you\ \[\[catch\]\]\ the\ result\ of\ an\ \[\[exec\]\]\ command,\ ''\$::errorCode''\ contains\ a\ wealth\ of\ information\ about\ what\ happened.\ \ See\ the\ \[exec\]\ page\ for\ how\ to\ take\ it\ apart.\nOn\ comp.lang.tcl,\ Ulrich\ Schoebel\ shows\ this\ as\ an\ example\ of\ how\ to\ get\ at\ the\ exit\ code\ of\ a\ command\ being\ \[exec\]'d\ in\ \[Tcl\]:\n----\n***Early\ throw\ discussion***\n\[\[The\ following\ discussion\ was\ held\ '''before'''\ Tcl\ 8.6\ added\ \[try\]/\[throw\].\]\]\n======\n\n\[MS\]:\ this\ will\ work\ as\ long\ as\ the\ ''unknown''\ proc\ has\ not\ been\ modified,\ and\ is\ relatively\ slow\ as\ the\ whole\ error\ processing\ machinery\ is\ also\ set\ in\ motion.\ If\ you\ want\ to\ use\ this\ approach\ in\ a\ more\ robust\ and\ fast\ manner,\ you\ may\ want\ to\ define\n\n======\n\ \ \ proc\ throw\ \{\{msg\ \{\}\}\ \{code\ 10\}\}\ \{\n\ \ \ \ \ \ \ return\ -code\ \$code\ \$msg\n\ \ \ \}\nThis\ will\ throw\ an\ exception,\ caught\ by\ ''catch''\;\ it\ will\ only\ be\ an\ error\ if\ code\ is\ set\ to\ \"error\"\ (or\ 1)\;\ do\ not\ use\ codes\ 0\ to\ 4\ in\ general\ as\ they\ have\ special\ meaning:\ \n\n\ \ \ 0\ \ \ \ \ \ \ TCL_OK\ \ \ \ \ \ \ \ \ normal\ return\ \n\ \ \ 1\ \ \ \ \ \ \ TCL_ERROR\ \ \ \ \ \ error\ return\n\ \ \ 2\ \ \ \ \ \ \ TCL_RETURN\ \ \ \ \ cause\ the\ *caller*\ to\ return\n\ \ \ 3\ \ \ \ \ \ \ TCL_BREAK\ \ \ \ \ \ call\ \[break\]\ in\ the\ caller\n\ \ \ 4\ \ \ \ \ \ \ TCL_CONTINUE\ \ \ call\ \[continue\]\ in\ the\ caller\n======none\n----\n***catch\ and\ external\ commands\ ***\n\nA\ common\ use\ for\ catch\ is\ when\ invoking\ external\ commands\ via\ \[exec\]\ .\ Since\ '''any'''\ non-zero\ return\ code\ would\ otherwise\ result\ in\ a\ raised\ error,\ one\ typically\ wraps\ the\ invocation\ with\ catch\ and\ then\ checks\ for\ the\ appropriate\ things.\ \ Since\ grep\ is\ just\ one\ example\ of\ a\ Unix\ command\ which\ uses\ a\ non-zero\ return\ code\ to\ mean\ something\ other\ than\ ''error'',\ one\ needs\ to\ be\ aware\ of\ cases\ like\ this\ when\ writing\ the\ exec.\n\n\[\[does\ someone\ have\ an\ idiom\ for\ execing\ a\ command,\ capturing\ the\ stdout,\ stderr,\ return\ code,\ etc.\ testing\ the\ return\ code\ and\ producing\ useful\ output\ based\ on\ stderr\ when\ appropriate,\ etc.?\ \ Answer:\n\"\[UNIX\ only\ exec\ wrapper\]\"\ is\ one\ model.\]\]\n**\ `catch`\ and\ stderr\ **\n----\n***catch\ and\ stderr***\nSomeone\ mentioned\ on\ \[comp.lang.tcl\]\ that\ it\ took\ them\ a\ while\ to\ understand\ that\ when\ you\ use\ catch\ and\ supply\ a\ variable,\ the\ output\ from\ the\ command\ that\ would\ go\ to\ stderr\ ends\ up\ in\ the\ variable.\nSomeone\ mentioned\ on\ comp.lang.tcl\ that\ it\ took\ them\ a\ while\ to\ understand\ that\ when\ you\ use\ catch\ and\ supply\ a\ variable,\ the\ output\ from\ the\ command\ that\ would\ go\ to\ stderr\ ends\ up\ in\ the\ variable.\n\n----\n***catch\ and\ exec\ status***\n\nOn\ comp.lang.tcl,\ Ulrich\ Schoebel\ shows\ this\ as\ an\ example\ of\ how\ to\ get\ at\ the\ exit\ code\ of\ a\ command\ being\ \[exec\]'d\ in\ \[Tcl\]:\n**\ `\[return\]`\ **\n\ if\ \{\[catch\ \{exec\ grep\ -q\ pippo\ /etc/passwd\}\ result\]\}\ \{\n\ \ #\ non-zero\ exit\ status,\ get\ it:\n\ \ set\ status\ \[lindex\ \$errorCode\ 2\]\n\ \}\ else\ \{\n\ \ #\ exit\ status\ was\ 0\n\ \ #\ result\ contains\ the\ result\ of\ your\ command\n\ \ set\ status\ 0\n\ \}\n\[JMN\]\ 2007-11-24:\n\[glennj\]:\ the\ above\ is\ ''slightly''\ lazy.\ \ The\ definitive\ method\ is\ seen\ as\ KBK's\ contribution\ to\ the\ \[exec\]\ page.\nI've\ been\ in\ the\ habit\ of\ using\ the\ idiom:\n\[LES\]:\ or\ should\ one\ rather\ follow\ advice\ given\ at\ \[exec\ and\ error\ information\]?\n\n----\n\[JMN\]\ 2007-11-24\n\n======\n\ if\ \{\[catch\ \{\n\ \ \ #somescript\n\ \}\ result_or_errormsg\]\}\ \{\n\ \ \ #handle\ error\n\ \}\ else\ \{\n\ \ \ #normal\ processing\n\ \}\nHowever..\ it's\ possible\ that\ a\ non-error\ situation\ in\ the\ script\ can\ give\ the\ return\ value\ of\ \[\[catch\]\]\ a\ value\ other\ than\ 0\nfor\ example,\ if\ you\ simply\ use\ a\ \[\[return\]\]\ \ \ to\ exit\ the\ script\ early.\nYou\ could\ use\ the\ extra\ ?optionsVarName?\ argument\ to\ examine\ the\ specific\ -code\ value,\ but\ in\ most\ cases\ that's\ more\ complicated\ than\ necessary,\nand\ I\ was\ hoping\ to\ keep\ the\ overall\ 'if\ structure'\ more\ or\ less\ in\ place.\nI'm\ now\ leaning\ towards\ replacing\ the\ above\ idiom\ with\ the\ following:\n\n======\n\ if\ \{1\ ==\ \[catch\ \{\n\ \ \ #somescript\n\ \}\ result_or_errormsg\]\}\ \{\n\ \ \ #handle\ error\n\ \}\ else\ \{\n\ \ \ #normal\ processing\n\ \}\nThis\ suffers\ from\ the\ problem\ that\ `return\ -code\ error`\ in\ the\ script\ will\ now\ not\ result\ in\ the\ error\ handling\ branch\ being\ run..\nThis\ suffers\ from\ the\ problem\ that\ 'return\ -code\ error'\ in\ the\ script\ will\ now\ not\ result\ in\ the\ error\ handling\ branch\ being\ run..\nAnyone\ got\ a\ neater\ way?\n\nI\ initially\ expected\ the\ return\ value\ of\ \[\[catch\]\]\ would\ align\ with\ \$code\ if\ 'return\ -code\ \$code'\ was\ used,\ but\ \[\[catch\]\]\ will\ always\ have\ the\ value\ 2\ if\ \[\[return\]\]\ is\ used.\n----\n***\ catch\ and\ background\ ***\n\nOften\ a\ Tcl/Tk\ program\ invokes\ an\ external\ command\ ,\ but\ needs\ the\ GUI\ to\nstay\ alive.\ The\ recommendation\ frequently\ is\ to\ use\ncatch\ \{exec\ somecommand\ &\}\n======\n\nHowever,\ what\ would\ be\ a\ strategy\ if\ you\ wanted\ to\ catch\ the\ output\ and\nsomecommand's\ return\ code?\nHowever,\ what\ would\ be\ a\ strategy\ if\ you\ wanted\ to\ catch\ the\ output\ and\ somecommand's\ return\ code?\n<<discussion>>\n----\n**See\ also**\n\ \ \ *\ \[exec\]\n\ \ \ *\ \[magic\ names\]\n\ \ \ *\ \[ucatch\]\ deunicodifies\ the\ error\ message\n\ \ \ *\ \[Tcl\ performance:\ catch\ vs.\ info\]\ for\ the\ slowness\ of\ catch.\n\n----\n!!!!!!\n\[Tcl\ syntax\ help\]\ |\n\[Arts\ and\ Crafts\ of\ Tcl-Tk\ Programming\]\ \n%|\[Category\ Command\]\ |\ \[Category\ Control\ Structure\]|%\n!!!!!! regexp2} CALL {my render catch ***COMMAND***\ncatch\ -\ Evaluate\ script\ and\ trap\ exceptional\ returns\ \n\n***USAGE***\n'''catch'''\ ''script''\ ?''messageVarName''?\ ?''optionsVarName''?\n**\ Synopsis\ **\n***CONTEXT***\nTCL\ core\ command\n\ \n***DESCRIPTION***\nThe\ '''catch'''\ command\ may\ be\ used\ to\ prevent\ errors\ from\ aborting\ command\ interpretation.\ \ '''Catch'''\ calls\ the\ Tcl\ interpreter\ recursively\ to\ execute\ ''script'',\ and\ always\ returns\ without\ raising\ an\ error,\ regardless\ of\ any\ errors\ that\ might\ occur\ while\ executing\ script.\n'''`catch`'''\ ''`script`''\ ?''`messageVarName`''?\ ?''`optionsVarName`''?\nIf\ ''script''\ raises\ an\ error,\ '''catch'''\ will\ return\ a\ non-zero\ integer\ value\ corresponding\ to\ one\ of\ the\ exceptional\ return\ codes\ (see\ tcl.h\ for\ the\ definitions\ of\ code\ values).\ \ If\ the\ ''messageVarName''\ argument\ is\ given,\ then\ the\ variable\ it\ names\ is\ set\ to\ the\ error\ message\ from\ interpreting\ script.\ If\ ''optionsVarName''\ is\ given,\ then\ the\ variable\ it\ names\ is\ set\ to\ a\ \[dict\]ionary\ describing\ details\ of\ the\ exceptional\ situation.\n\nIf\ ''script''\ does\ not\ raise\ an\ error,\ catch\ will\ return\ '''0'''\ (TCL_OK)\ and\ set\ the\ variable\ to\ the\ value\ returned\ from\ script.\n\nNote\ that\ '''catch'''\ catches\ all\ exceptions,\ including\ those\ generated\ by\ '''\[break\]'''\ and\ '''\[continue\]''',\ ''and\ '''\[return\]''''',\ as\ well\ as\ errors.\ The\ only\ errors\ that\ are\ not\ caught\ are\ syntax\ errors\ found\ when\ the\ script\ is\ compiled.\ \ This\ is\ because\ the\ catch\ command\ only\ catches\ errors\ during\ runtime.\ \ When\ the\ catch\ statement\ is\ compiled,\ the\ script\ is\ compiled\ as\ well\ and\ any\ syntax\ errors\ will\ generate\ a\ Tcl\ error.\ \ \ \n\ \n***MAN\ PAGE***\nhttp://www.tcl.tk/man/tcl8.5/TclCmd/catch.htm\n\ \n***SEE\ ALSO***\n\[break\],\ \[continue\],\ \[return\],\ \[error\],\ \[errorCode\],\ \[errorInfo\],\ \[try\]\n**\ Documentation\ **\n***EXAMPLES***\nThe\ '''catch'''\ command\ may\ be\ used\ in\ an\ '''\[if\]'''\ to\ branch\ based\ on\ the\ success\ of\ a\ script.\ \ \nif\ \{\[catch\ \{open\ \$someFile\ w\}\ fid\]\}\ \{\n\ if\ \{\ \[catch\ \{open\ \$someFile\ w\}\ fid\]\ \}\ \{\n\ \ \ puts\ stderr\ \"Could\ not\ open\ \$someFile\ for\ writing\\n\$fid\"\n\ \ \ exit\ 1\n\ \}\n\n<<discussion>>\n\nThe\ '''catch'''\ command\ will\ not\ catch\ compiled\ syntax\ errors.\ \ The\ first\ time\ proc\ '''foo'''\ is\ called,\ the\ body\ will\ be\ compiled\ and\ a\ Tcl\ error\ will\ be\ generated.\ \ \ \n\n======\n%\ proc\ foo\ \{\}\ \{\n\ \ \ catch\ \{expr\ \{1\ +-\ \}\}\n\ \}\n\n%\ set\ a\ \[foo\]\n1\n======\n\nWhen\ foo\ is\ executed,\ \n(from:\ Tcl\ Help\;\ bold\ words\ added\ by\ \[RS\])\n\n\[DKF\]:\ Actually,\ it's\ catching\ the\ syntax\ error\ just\ fine\;\ that\ it\ didn't\ used\ to\ was\ a\ bug\ in\ earlier\ versions\ of\ the\ bytecode\ compiler,\ and\ that\ was\ fixed\ in\ around\ the\ 8.4\ timeframe.\n\n----\n***Catching\ large\ chunks\ of\ code***\n\n\nWhy\ is\ it\ a\ bad\ idea\ to\ \"catch\"\ large\ chunks\ of\ code?\ Because\ Tcl\ stops\ execution\ of\ the\ code\ as\ soon\ as\ it\ encounters\ an\ error.\ This\ behavior\ can\ lead\ to\ problems\ like\ this:\n\n======\n\ \ \ \ #\ I've\ got\ an\ open\ socket\ whose\ handle's\ stored\ in\ fid\n\ \ \ \ catch\ \{\n\ \ \ \ \ \ \ \ puts\ \$fid\ \"Here's\ my\ last\ message.\"\n\ \ \ \ \ \ \ \ close\ \$fid\n\ \ \ \ \}\ err\nIf\ the\ \"puts\"\ command\ generates\ an\ error,\ \"catch\"\ detects\ that\ and\ stops\ execution\ of\ the\ code\ block.\ You\ never\ get\ around\ to\ closing\ the\ channel.\ It's\ better\ practice\ to\ put\ separate\ \"catch\"\ commands\ around\nboth\ the\ \"puts\"\ and\ the\ \"close\"\ commands\ to\ detect\ errors\ in\ either\ case\ and\ handle\ them\ appropriately.\n\nThis\ is\ a\ different\ style\ of\ programming\ than\ in\ a\ language\ like\ Java.\ In\ Java,\ you\ can\ have\ a\ variety\ of\ exceptions,\ each\ represented\ by\ a\ different\ class,\ that\ signal\ different\ types\ of\ error\ conditions.\ Then\nin\ a\ \"try\"\ block,\ you\ can\ test\ for\ the\ different\ types\ of\ error\ conditions\ separately\ and\ handle\ them\ in\ different\ ways.\ (My\ complaint\ about\ Java\ is\ that\ there\ seems\ to\ be\ so\ many\ different\ classes,\ I'm\ often\ at\ a\ loss\ as\ to\ which\ ones\ I\ should\ be\ testing\ for.)\ In\ contrast,\ Tcl\ generally\ has\ only\ one\ type\ of\ error.\ In\ theory,\ we\ could\ use\ different\ return\ codes\ to\ signal\ different\ types\ of\ error,\ but\ in\ practice\ this\ is\ hardly\ ever\ used.\n\n----\n\nI\ think\ it\ is\ extreme\ parochialism\ to\ state\ \"it's\ a\ bad\ idea\ to\ code\ this/that\ way\".\ \ It\ is\ perfectly\ reasonable\ to\ catch\ \"large\"\ chunks:\n\n======\n\ \ if\ \{\ \[\ catch\ \{\n\ \ \ \ close\ \$fid\n\}\ err\ \]\ \}\ \{\n\ \}\ err\ \]\ \}\ \{\n\ \ \ \ return\ -code\ error\ \$err\n\}\n\ \}\nIf\ you\ catch\ \"large\"\ chunks\ you\ can\ at\ least\ have\ a\ program\ that\ can\ tolerate\ some\ errors\ that\ you\ did\ not\ anticipate.\ It\ is\ certainly\ better\ to\ fix\ problems\ the\ first\ time\ they\ appear,\ but\ tinkering\ with\ the\ code\ on\ a\ live\ system\ is\ rather\ poor\ practice.\n\nMost\ users\ would\ rather\ ''not''\ have\ the\ software\ come\ to\ a\ screeching\ halt\ on\ every\ unanticipated\ error.\ \ -'''PSE'''\n\n\n----\n\n\n======\nset\ resource\ \[some\ allocator\]\nif\ \{\[set\ result\ \[catch\ \{some\ code\ with\ \$resource\}\ resulttext\]\]\}\ \{\n\ \ \ \ #\ remember\ global\ error\ state,\ as\ de-allocation\ may\ overwrite\ it\n\ \ \ \ set\ einfo\ \$::errorInfo\n\ \ \ \ set\ ecode\ \$::errorCode\n\n\ \ \ \ #\ free\ the\ resource,\ ignore\ nested\ errors\n\ \ \ \ catch\ \{deallocate\ \$resource\}\n\n\ \ \ \ #\ report\ the\ error\ with\ original\ details\n\ \ \ \ return\ -code\ \$result\ \\\n\ \ \ \ \ \ \ \ \ \ \ -errorcode\ \$ecode\ \\\n\ \ \ \ \ \ \ \ \ \ \ -errorinfo\ \$einfo\ \\\n\ \ \ \ \ \ \ \ \ \ \ \$resulttext\n\}\ndeallocate\ \$resource\n\ncontinue\ normally\n======\n\nBesides\ a\ full-scale\ Java-style\ `\[try\]`\ implementation\ with\ all\ kinds\ of\ functionality\ for\ the\ catch\ branches,\ this\ could\ probably\ also\ be\ improved\ with\ a\ simpler\ command\ ''withresource'',\ that\ doesn't\ have\ the\ catch\ branch\ functionality,\ like\ this:\nBesides\ a\ full-scale\ Java-style\ \[try\]\ implementation\ with\ all\ kinds\ of\ functionality\ for\ the\ catch\ branches,\ this\ could\ probably\ also\ be\ improved\ with\ a\ simpler\ command\ ''withresource'',\ that\ doesn't\ have\ the\ catch\ branch\ functionality,\ like\ this:\n======\n\ set\ resource\ \[some\ allocator\]\n\ withresource\ \{\n\ \ \ \ \ some\ code\ with\ \$resource\n\ \}\ finally\ \{\n\ \ \ \ \ #\ this\ would\ be\ executed\ always,\ even\ in\ case\ of\ error\n\ \ \ \ \ deallocate\ \$resource\n\ \}\ncontinue\ normally\n\ continue\ normally\n\[HaO\]\ 2012-02-17:\ Within\ the\ upper\ code,\ one\ may\ use\ the\ tcl\ 8.5\ feature\ of\ an\ option\ dict\ returned\ by\ catch.\n\[HaO\]\ within\ the\ upper\ code,\ one\ may\ use\ the\ tcl\ 8.5\ feature\ of\ an\ option\ dict\ returned\ by\ catch.\nHere\ is\ the\ modified\ code\ which\ does\ the\ same:\n\nset\ resource\ \[some\ allocator\]\nif\ \{\[set\ result\ \[catch\ \{some\ code\ with\ \$resource\}\ resulttext\ resultoptions\]\]\}\ \{\n\ \ \ \ #\ free\ the\ resource,\ ignore\ nested\ errors\n\n\ \ \ \ catch\ \{deallocate\ \$resource\}\n\ \ \ \ \n\ \ \ \ #\ report\ the\ error\ with\ original\ details\n\ \ \ \ dict\ unset\ resultoptions\ -level\n\ \ \ \ return\ -options\ \$resultoptions\ \$resulttext\n\ \ \ \ return\ -options\ \$resultoptions\ndeallocate\ \$resource\n\ncontinue\ normally\n======\n\n2015-12-07:\ \[heinrichmartin\]\ proposed\ on\ clt\ to\ use\ `\[dict\ incr\]\ resultoptions\ -level`\ instead\ of\ `\[dict\ unset\]\ resultoptions\ -level`.\ \ Results\ in\ the\ same\ but\ might\ be\ more\ straightforward.\n----\n***Old\ catch\ bug\ discussed***\n\n\[MS\]:\ ''Oops,\ forgot\ to\ mention\ it\ here:\ this\ bug\ was\ closed\ on\ 2000-10-25,\ it\ is\ fixed\ in\ tcl8.4a4.''\n\nNote\ that\ the\ bytecode\ compiling\ of\ \[\[catch\]\]\ in\ Tcl\ 8.x\ has\ a\ bug.\ '''\[catch\]'''\ will\ inappropriately\ catch\ errors\ in\ the\ substitution\ of\ its\ arguments:\n\n\ %\ #\ should\ return\ 'foo'\n\ %\ catch\ \[error\ foo\]\n\ 1\n\nCompare\ with\ Tcl\ 7.6:\n\n\ %\ catch\ \[error\ foo\]\n\ foo\n\nTo\ work\ around\ the\ bug,\ defeat\ the\ bytecode\ compiler\ by\ generating\ '''\[catch\]''':\n\n\ %\ \[format\ catch\]\ \[error\ foo\]\n\ foo\n\nTrack\ Sourceforge\ bug\ #\ 119184\ to\ learn\ if/when\ this\ bug\ is\ fixed.\nhttp://sourceforge.net/bugs/?func=detailbug&bug_id=119184&group_id=10894\n\n'''DGP'''\n\n----\n***Catch\ return\ example***\n\nExample\ for\ caught\ return,\ from\ a\ posting\ of\ \[George\ Petasis\]\ in\ \[the\ comp.lang.tcl\ newsgroup\]:\n======\n\ %\ proc\ foo\ \{\}\ \{\n\ \ \ \ \ \ \ \ puts\ \"catch\ result\ is\ :\[catch\ \{\ return\}\]\"\n\ \ \ \ \ \ \ \ puts\ \"after\ return\"\n\ \}\ \n\ %\ foo\n\ catch\ result\ is\ :2\n\ after\ return\ \n\n----\n***Catching\ break,\ continue,\ error,\ and\ return***\n\nFor\ a\ more\ complex\ worked\ example\ of\ catching\ \[\[break\]\],\ \[\[continue\]\],\ \[\[error\]\]\ and\ \[\[return\]\],\ this\ Wiki\ has\ a\ pure\ Tcl\ implementation\ of\ a\ Java-style\ \[try\ ...\ finally\ ...\]\ construct.\ \ --\ \[KBK\]\ 24\ Dec\ 2000\n**\ `\[catch\]`\ and\ `\[exec\]`\ **\n----\nThe\ options\ dictionary\ from\ catching\ a\ call\ to\ `\[exec\]`\ contains\ a\ wealth\ of\nWhen\ you\ \[\[catch\]\]\ the\ result\ of\ an\ \[\[exec\]\]\ command,\ ''\$::errorCode''\ contains\ a\ wealth\ of\ information\ about\ what\ happened.\ \ See\ the\ \[exec\]\ page\ for\ how\ to\ take\ it\ apart.\nOn\ comp.lang.tcl,\ Ulrich\ Schoebel\ shows\ this\ as\ an\ example\ of\ how\ to\ get\ at\ the\ exit\ code\ of\ a\ command\ being\ \[exec\]'d\ in\ \[Tcl\]:\n----\n***Early\ throw\ discussion***\n\[\[The\ following\ discussion\ was\ held\ '''before'''\ Tcl\ 8.6\ added\ \[try\]/\[throw\].\]\]\n======\n\n\[MS\]:\ this\ will\ work\ as\ long\ as\ the\ ''unknown''\ proc\ has\ not\ been\ modified,\ and\ is\ relatively\ slow\ as\ the\ whole\ error\ processing\ machinery\ is\ also\ set\ in\ motion.\ If\ you\ want\ to\ use\ this\ approach\ in\ a\ more\ robust\ and\ fast\ manner,\ you\ may\ want\ to\ define\n\n======\n\ \ \ proc\ throw\ \{\{msg\ \{\}\}\ \{code\ 10\}\}\ \{\n\ \ \ \ \ \ \ return\ -code\ \$code\ \$msg\n\ \ \ \}\nThis\ will\ throw\ an\ exception,\ caught\ by\ ''catch''\;\ it\ will\ only\ be\ an\ error\ if\ code\ is\ set\ to\ \"error\"\ (or\ 1)\;\ do\ not\ use\ codes\ 0\ to\ 4\ in\ general\ as\ they\ have\ special\ meaning:\ \n\n\ \ \ 0\ \ \ \ \ \ \ TCL_OK\ \ \ \ \ \ \ \ \ normal\ return\ \n\ \ \ 1\ \ \ \ \ \ \ TCL_ERROR\ \ \ \ \ \ error\ return\n\ \ \ 2\ \ \ \ \ \ \ TCL_RETURN\ \ \ \ \ cause\ the\ *caller*\ to\ return\n\ \ \ 3\ \ \ \ \ \ \ TCL_BREAK\ \ \ \ \ \ call\ \[break\]\ in\ the\ caller\n\ \ \ 4\ \ \ \ \ \ \ TCL_CONTINUE\ \ \ call\ \[continue\]\ in\ the\ caller\n======none\n----\n***catch\ and\ external\ commands\ ***\n\nA\ common\ use\ for\ catch\ is\ when\ invoking\ external\ commands\ via\ \[exec\]\ .\ Since\ '''any'''\ non-zero\ return\ code\ would\ otherwise\ result\ in\ a\ raised\ error,\ one\ typically\ wraps\ the\ invocation\ with\ catch\ and\ then\ checks\ for\ the\ appropriate\ things.\ \ Since\ grep\ is\ just\ one\ example\ of\ a\ Unix\ command\ which\ uses\ a\ non-zero\ return\ code\ to\ mean\ something\ other\ than\ ''error'',\ one\ needs\ to\ be\ aware\ of\ cases\ like\ this\ when\ writing\ the\ exec.\n\n\[\[does\ someone\ have\ an\ idiom\ for\ execing\ a\ command,\ capturing\ the\ stdout,\ stderr,\ return\ code,\ etc.\ testing\ the\ return\ code\ and\ producing\ useful\ output\ based\ on\ stderr\ when\ appropriate,\ etc.?\ \ Answer:\n\"\[UNIX\ only\ exec\ wrapper\]\"\ is\ one\ model.\]\]\n**\ `catch`\ and\ stderr\ **\n----\n***catch\ and\ stderr***\nSomeone\ mentioned\ on\ \[comp.lang.tcl\]\ that\ it\ took\ them\ a\ while\ to\ understand\ that\ when\ you\ use\ catch\ and\ supply\ a\ variable,\ the\ output\ from\ the\ command\ that\ would\ go\ to\ stderr\ ends\ up\ in\ the\ variable.\nSomeone\ mentioned\ on\ comp.lang.tcl\ that\ it\ took\ them\ a\ while\ to\ understand\ that\ when\ you\ use\ catch\ and\ supply\ a\ variable,\ the\ output\ from\ the\ command\ that\ would\ go\ to\ stderr\ ends\ up\ in\ the\ variable.\n\n----\n***catch\ and\ exec\ status***\n\nOn\ comp.lang.tcl,\ Ulrich\ Schoebel\ shows\ this\ as\ an\ example\ of\ how\ to\ get\ at\ the\ exit\ code\ of\ a\ command\ being\ \[exec\]'d\ in\ \[Tcl\]:\n**\ `\[return\]`\ **\n\ if\ \{\[catch\ \{exec\ grep\ -q\ pippo\ /etc/passwd\}\ result\]\}\ \{\n\ \ #\ non-zero\ exit\ status,\ get\ it:\n\ \ set\ status\ \[lindex\ \$errorCode\ 2\]\n\ \}\ else\ \{\n\ \ #\ exit\ status\ was\ 0\n\ \ #\ result\ contains\ the\ result\ of\ your\ command\n\ \ set\ status\ 0\n\ \}\n\[JMN\]\ 2007-11-24:\n\[glennj\]:\ the\ above\ is\ ''slightly''\ lazy.\ \ The\ definitive\ method\ is\ seen\ as\ KBK's\ contribution\ to\ the\ \[exec\]\ page.\nI've\ been\ in\ the\ habit\ of\ using\ the\ idiom:\n\[LES\]:\ or\ should\ one\ rather\ follow\ advice\ given\ at\ \[exec\ and\ error\ information\]?\n\n----\n\[JMN\]\ 2007-11-24\n\n======\n\ if\ \{\[catch\ \{\n\ \ \ #somescript\n\ \}\ result_or_errormsg\]\}\ \{\n\ \ \ #handle\ error\n\ \}\ else\ \{\n\ \ \ #normal\ processing\n\ \}\nHowever..\ it's\ possible\ that\ a\ non-error\ situation\ in\ the\ script\ can\ give\ the\ return\ value\ of\ \[\[catch\]\]\ a\ value\ other\ than\ 0\nfor\ example,\ if\ you\ simply\ use\ a\ \[\[return\]\]\ \ \ to\ exit\ the\ script\ early.\nYou\ could\ use\ the\ extra\ ?optionsVarName?\ argument\ to\ examine\ the\ specific\ -code\ value,\ but\ in\ most\ cases\ that's\ more\ complicated\ than\ necessary,\nand\ I\ was\ hoping\ to\ keep\ the\ overall\ 'if\ structure'\ more\ or\ less\ in\ place.\nI'm\ now\ leaning\ towards\ replacing\ the\ above\ idiom\ with\ the\ following:\n\n======\n\ if\ \{1\ ==\ \[catch\ \{\n\ \ \ #somescript\n\ \}\ result_or_errormsg\]\}\ \{\n\ \ \ #handle\ error\n\ \}\ else\ \{\n\ \ \ #normal\ processing\n\ \}\nThis\ suffers\ from\ the\ problem\ that\ `return\ -code\ error`\ in\ the\ script\ will\ now\ not\ result\ in\ the\ error\ handling\ branch\ being\ run..\nThis\ suffers\ from\ the\ problem\ that\ 'return\ -code\ error'\ in\ the\ script\ will\ now\ not\ result\ in\ the\ error\ handling\ branch\ being\ run..\nAnyone\ got\ a\ neater\ way?\n\nI\ initially\ expected\ the\ return\ value\ of\ \[\[catch\]\]\ would\ align\ with\ \$code\ if\ 'return\ -code\ \$code'\ was\ used,\ but\ \[\[catch\]\]\ will\ always\ have\ the\ value\ 2\ if\ \[\[return\]\]\ is\ used.\n----\n***\ catch\ and\ background\ ***\n\nOften\ a\ Tcl/Tk\ program\ invokes\ an\ external\ command\ ,\ but\ needs\ the\ GUI\ to\nstay\ alive.\ The\ recommendation\ frequently\ is\ to\ use\ncatch\ \{exec\ somecommand\ &\}\n======\n\nHowever,\ what\ would\ be\ a\ strategy\ if\ you\ wanted\ to\ catch\ the\ output\ and\nsomecommand's\ return\ code?\nHowever,\ what\ would\ be\ a\ strategy\ if\ you\ wanted\ to\ catch\ the\ output\ and\ somecommand's\ return\ code?\n<<discussion>>\n----\n**See\ also**\n\ \ \ *\ \[exec\]\n\ \ \ *\ \[magic\ names\]\n\ \ \ *\ \[ucatch\]\ deunicodifies\ the\ error\ message\n\ \ \ *\ \[Tcl\ performance:\ catch\ vs.\ info\]\ for\ the\ slowness\ of\ catch.\n\n----\n!!!!!!\n\[Tcl\ syntax\ help\]\ |\n\[Arts\ and\ Crafts\ of\ Tcl-Tk\ Programming\]\ \n%|\[Category\ Command\]\ |\ \[Category\ Control\ Structure\]|%\n!!!!!!} CALL {my revision catch} CALL {::oo::Obj7426151 process revision/catch} CALL {::oo::Obj7426149 process}

-errorcode

NONE

-errorinfo

Unknow state transition: LINE -> END
    while executing
"error $msg"
    (class "::Wiki" method "render_wikit" line 6)
    invoked from within
"my render_$default_markup $N $C $mkup_rendering_engine"
    (class "::Wiki" method "render" line 8)
    invoked from within
"my render $name $C"
    (class "::Wiki" method "revision" line 31)
    invoked from within
"my revision $page"
    (class "::Wiki" method "process" line 51)
    invoked from within
"$server process [string trim $uri /]"

-errorline

4