Thanks.
function [] = ctrlcthrow
% Call the function, then hit ctrl+c.
cnt = 1;
try
while true
cnt = cnt +1;
end
catch
disp('Error caught')
end
No. In older releases, Ctrl-C could be caught by TRY/CATCH; that changed a
while ago. [When Ctrl-C was caught, you could get into a situation where
there was no way, short of terminating the MATLAB process, to end your
code.] Ctrl-C is one of the bigger hammers -- it will terminate the
currently running program and return to the command prompt at the next
opportunity MATLAB can do so.
However, if you want to do some sort of cleanup after Ctrl-C but before
MATLAB returns to the prompt (say to close a file or a figure window) then
you can use an onCleanup object to do so.
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/oncleanup.html
--
Steve Lord
sl...@mathworks.com
That's correct, onCleanup was introduced in MATLAB 7.6 (R2008a).
http://www.mathworks.com/access/helpdesk/help/techdoc/rn/brjk1q5-1.html#brjk1q5-9
I can't really think of a good way for you to perform some of your own
cleanup after a Ctrl-C in release R2006b. MATLAB will clean up the
variables that are in the function workspace, but doesn't perform cleanup
like closing file handles or the like.
--
Steve Lord
sl...@mathworks.com