MATLAB: OnCleanup and script

oncleanuponcleanup and parfortry/catch

Hello.
I'm using a parfor loop,but sometimes I stop its execution with ctrl+c, so I would like to execute the command "matlabpool close" immediately in order not to leave the processes on. I have recommended to use onCleanup function,but I have read that I need to use it within a function and not in a script, and I've got a script, owe to that fact I wonder if I could do the same with a try/catch sentence, is it possible?
thanks!

Best Answer

No. try/catch cannot catch a control-c .
I would suggest just converting your script in to a function: doing so is likely to be far easier than working around the issue.