Handle a signal: Difference between revisions

→‎{{header|Tcl}}: Illustrated more of 8.6's try/trap syntax
No edit summary
(→‎{{header|Tcl}}: Illustrated more of 8.6's try/trap syntax)
Line 275:
 
=={{header|Tcl}}==
Core Tcl does not have signal handling. However the [http://expect.nist.gov/ Expect] and [http://tclx.sourceforge.net/ TclX] extensions do:
 
Using Expect:
Line 333:
puts "infinite loop interrupted, but not on SIGINT: $::errorInfo"
}
}</lang>
With Tcl 8.6, that would be written as:
<lang tcl>package require Tclx
 
signal error sigint
 
set start_time [clock seconds]
proc infinite_loop {} {
while 1 {
puts [incr n]
after 500
}
}
try {
infinite_loop
} trap {POSIX SIG SIGINT} {} {
puts "elapsed time: [expr {[clock seconds] - $start_time}] seconds"
}</lang>
Anonymous user