<i>man try: better explain what happens if trap and finally executes regarding order and return value</i>.
by
.
D 2021-08-24T13:41:16.498
J assignee nobody
J closer nobody
J cmimetype text/x-fossil-wiki
J comment Dear\sTCL\steam,\r\n\r\nI\sam\shappy\swith\sthe\stry\scommand.\r\nMay\sI\spropose\ssome\senhancements\sto\sthe\sman\spage\sregarding\sa\strap\sand\sa\sfinally\sclause.\r\n\r\nIMHO,\sthe\sfollowing\sinformation\smay\sbe\sadded:\r\n\r\n<h2>Execution\sorder</h2>\r\n\r\nIf\sa\son/trap\sand\sa\sfinally\sclause\sis\spresent\sand\sexecuted,\sthe\strap\scode\sis\sexecuted\sbefore\sthe\sfinally\sclause.\r\n\r\n<h2>Return\svalue</h2>\r\n\r\nIf\sa\son/trap\sclause\sand\sa\sfinally\sclause\sis\spresent,\sthe\sfollowing\srules\scomply\sconcerning\sreturn\svalues:\r\n\r\n\s\s\s\s*\s\s\s\sIf\sonly\sthe\strap\sclause\sexecutes\sa\sreturn/error\scommand,\sthis\sreturn\svalue\sis\sreturned\sfrom\sthe\sprocedure\r\n\s\s\s\s*\s\s\s\sIf\sthe\sfinally\sclause\sexecutes\sa\sreturn/error\scommand,\sthis\sreturn\svalue\sis\sreturned\sfrom\sthe\sproc.\r\n\r\n<h2>Example\sfor\sorder\sand\sreturn\svalues</h2>\r\n\r\nAn\sexample\smay\sbe\sadded\slike\sthis:\r\n\r\n<verbatim>\r\nproc\swriteFile\s{}\s{\r\n\s\s\s\sset\sf\s[open\s/some/file/name\sa]\r\n\s\s\s\stry\s{\r\n\s\s\s\s\s\s\s\sputs\s$f\s"some\smessage"\r\n\s\s\s\s}\son\serror\s{}\s{\r\n\s\s\s\s\s\s\s\sputs\sstderr\s"Write\serror"\r\n\s\s\s\s\s\s\s\sreturn\s0\r\n\s\s\s\s\s\s\s\s#\s0\sis\sthe\sreturn\svalue\sin\scase\sof\san\serror\r\n\s\s\s\s\s\s\s\s#\sThe\sfinally\sclause\sis\sexecuted\safter\sthe\sreturn\sto\sclose\sthe\sfile\r\n\s\s\s\s}\sfinally\s{\r\n\s\s\s\s\s\s\s\sclose\s$f\r\n\s\s\s\s}\r\n\s\s\s\sreturn\s1\r\n}\s\r\n}\r\n</verbatim>\r\n\r\nIMHO\sthis\sexample\sreally\sshows\sthe\spower\sand\suse-case\sof\sthe\sfinally\sclause.\r\n\r\nWhat\sdo\syou\sthink?\r\n\r\nHarald
J is_private 0
J login oehhar
J priority 5\sMedium
J resolution None
J severity Minor
J status Open
J submitter oehhar
J subsystem -\sNew\sBuiltin\sCommands
J title man\stry:\sbetter\sexplain\swhat\shappens\sif\strap\sand\sfinally\sexecutes\sregarding\sorder\sand\sreturn\svalue
J type Bug
K 648e2f961e7b20635b28219dda23917bc4d73f66
U oehhar
Z ff07380c0eff9781228e2ad68eaf7197