Handle a signal: Difference between revisions

Added MATLAB examples
(Added JavaScript (NodeJS). Removed omit from JavaScript)
(Added MATLAB examples)
Line 530:
wait
</lang>
 
=={{header|MATLAB}}==
MATLAB versions 6.5 (R13) and newer can no longer catch CTRL+C with a try-catch block. The onCleanup() function was introduced in version 7.6 (R2008a), possibly specifically for this situation. However, the designated onCleanup() function will execute no matter how the function ends (task completion, CTRL+C, exception), and CTRL+C will still cause an exception to be thrown and displayed.
{{works with|MATLAB|Version 7.6 (R2008a) and later}}
<lang MATLAB>function sigintHandle
k = 1;
tic
catchObj = onCleanup(@toc);
while true
pause(0.5)
fprintf('%d\n', k)
k = k+1;
end
end</lang>
{{out}}
<pre>>> sigintCleanup
1
2
3
4
5
6
Elapsed time is 3.348772 seconds.
??? Operation terminated by user during ==> sigintHandle at 6</pre>
{{works with|MATLAB|Version 6.1 (R12.1) and earlier}}
{{untested|MATLAB}}
<lang MATLAB>function sigintHandle
k = 1;
tic
try
while true
pause(0.5)
fprintf('%d\n', k)
k = k+1;
end
catch me
toc
rethrow me
end
end</lang>
 
=={{header|OCaml}}==
Anonymous user