Exception Handling
The definition exception handling could be misleading. This is a mechanism based on the command abort_page, rather than a language specific exception handling as it's done in tcl8.6 or through the 'catch' core command.
abort_page terminates a script and returns control to the module core with a special return code. The module checks the error code and skips subsequent scripts (AfterScript) printing an error message and dropping already sent page contents from the output channel.
this is a proposal for a new handling of this mechanism that hopefully should preserve existing code maintaining full compatibility:
AbortScript: script that gets run if abort_page is called by the content generator or by AfterScript.
ForceAfterScript (or FinalAfterScript or whatever): it's run anyway regardless the completion code of the script that ran before in the request process
Command abort_page will have an internal status flag 'aborting' to be set in the module globals. This flag is set to 0 at the very beginning of the request processing (Rivet_SendContent). 'abort_page' tests this flag, if 0 it gets set as 1 and the command returns TCL_ERROR setting the usual error info that are trapped in Rivet_ExecuteAndCheck.
Any subsequent call to the command will return TCL_OK disabling its effects within ForceAfterScript (just making sure that it cannot be interrupted in this way).
'abort_page' will accept an argument to be later retrived with a new command 'abort_condition'. AbortScript may check this condition variable to branch into different blocks of code.
Basically, the code in Rivet_ExecuteAndCheck where the abort condition is checked
if (strcmp (Tcl_GetString (errorCodeElementObj), "RIVET") == 0) {
- ..
}
should test the definition of a new conf variable rivet_abort_script and execute it if defined. The whole function has to also check for the new conf variable rivet_force_script and run it anyway before printing the headers and flushing the channel.