Index: openacs-4/packages/acs-tcl/tcl/exception-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/exception-procs.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/packages/acs-tcl/tcl/exception-procs.tcl 27 Oct 2014 16:40:06 -0000 1.4 +++ openacs-4/packages/acs-tcl/tcl/exception-procs.tcl 7 Aug 2017 23:47:59 -0000 1.5 @@ -1,57 +1,79 @@ ad_library { - @author rhs@mit.edu - @creation-date 2000-09-09 - @cvs-id $Id$ + @author rhs@mit.edu + @creation-date 2000-09-09 + @cvs-id $Id$ } ad_proc -private ad_raise {exception {value ""}} { - @author rhs@mit.edu - @creation-date 2000-09-09 + @author rhs@mit.edu + @creation-date 2000-09-09 - Raise an exception. + Raise an exception. - If you use this I will kill you. + If you use this I will kill you. } { - return -code error -errorcode [list "AD" "EXCEPTION" $exception] $value + return -code error -errorcode [list "AD" "EXCEPTION" $exception] $value } +ad_proc ad_exception {errorCode} { + @author gustaf.neumann@wu-wien.ac.at + @creation-date 2015-12-31 + + Check if the exception was caused by ad_raise (i.e. was an OpenACS + exception) + + @return ad_exception value or empty, in case the exception had other causes +} { + lassign $errorCode flag type value + if {$flag eq "AD" && $type eq "EXCEPTION"} { + return $value + } + return "" +} + ad_proc -private ad_try {code args} { - @author rhs@mit.edu - @creation-date 2000-09-09 + @author rhs@mit.edu + @creation-date 2000-09-09 - Executes $code, catches any exceptions thrown by ad_raise and runs - any matching exception handlers. + Executes $code, catches any exceptions thrown by ad_raise and runs + any matching exception handlers. - If you use this I will kill you. + If you use this I will kill you. - @see with_finally - @see with_catch + @see with_finally + @see with_catch } { - if {[set errno [catch {uplevel $code} result]]} { - if {$errno == 1 - && [lindex $::errorCode 0] eq "AD" - && [lindex $::errorCode 1] eq "EXCEPTION" - } { - set exception [lindex $::errorCode 2] + if {[set errno [catch {uplevel $code} result]]} { + if {$errno == 1 + && [lindex $::errorCode 0] eq "AD" + && [lindex $::errorCode 1] eq "EXCEPTION" + } { + set exception [lindex $::errorCode 2] - set matched 0 - for {set i 0} {$i < [llength $args]} {incr i 3} { - if {[string match [lindex $args $i] $exception]} { - set matched 1 - break - } - } + set matched 0 + for {set i 0} {$i < [llength $args]} {incr i 3} { + if {[string match [lindex $args $i] $exception]} { + set matched 1 + break + } + } - if {$matched} { - upvar [lindex $args $i+1] var - set var $result - set errno [catch {uplevel [lindex $args $i+2]} result] - } - } + if {$matched} { + upvar [lindex $args $i+1] var + set var $result + set errno [catch {uplevel [lindex $args $i+2]} result] + } + } - return -code $errno -errorcode $::errorCode -errorinfo $::errorInfo $result - } + return -code $errno -errorcode $::errorCode -errorinfo $::errorInfo $result + } } + +# Local variables: +# mode: tcl +# tcl-indent-level: 4 +# indent-tabs-mode: nil +# End: