try — Catch error and exception conditions


::rivet::try ?script? ?script? ?handlers? ?finally script?


::rivet::try wraps the core language command and simply traps exceptions that might have raised by ::rivet::abort_page and ::rivet::exit to throw them again and thus causing AbortScript to be executed.

If neither ::rivet::abort_page nor ::rivet::exit are called from ?script? then any handlers specified in the command are tested for execution. Thus ::rivet::try can transparently be used as a replacement for Tcl's own try and it's needed if you want ?script? to safely bail out to AbortScript

This script shows how ::rivet:try handles different exceptions or errors. You can drive this script within mod_rivet adding the arguments fail or abort or exit to its URL. You can handle the exit and abort cases with an AbortScript. See the section called “Rivet Apache Directives”

<html><?::rivet::try {
	if {[::rivet::var_qs exists exit]} {
	    ::rivet::exit 100
	} elseif {[::rivet::var_qs exists abort]} {
	} elseif {[::rivet::var_qs exists fail]} {
	    # this is just a non existent command
	} else {
	    puts "<b>OK</b>"

} on error {e o} {
  puts "catching error -&gt; $e<br/>"
  dict for {fd fv} $o {

   puts "$fd --&gt;&gt; $fv<br/>"


Placing this code in a file (try.rvt) on the web server DocumentRoot directory and setting for example the browser to http://localhost/try.rvt?fail=1.

catching error -> invalid command name "wrong_command"
-errorcode -->> TCL LOOKUP COMMAND wrong_command
-code -->> 1
-level -->> 0
-errorstack -->> INNER {invokeStk1 wrong_command} UP 1
-errorinfo -->> invalid command name "wrong_command" while executing "wrong_command" ("::try" body line 9)
-errorline -->> 9