try — Catch error and exception conditions
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]} {
::rivet::abort_page
} elseif {[::rivet::var_qs exists fail]} {
# this is just a non existent command
wrong_command
} else {
puts "<b>OK</b>"
}
} on error {e o} {
puts "catching error -> $e<br/>"
dict for {fd fv} $o {
puts "$fd -->> $fv<br/>"
}
}
?></html>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