0

Often, especially during development of scripts and functions, I stop my MATLAB programs using Ctrl+C However, sometimes some things need to be handled even after this, such as closing file handles.

The messages displayed after pressing Ctrl+C look a lot like a regular stacktrace, but a try-catch statement does not catch it, so exception-safe handing is not enough. The onCleanup functionality does work, but only in functions. The suggestion of using dbstop if error is also not a proper solution as it requires manually resolving any issues.

Are there other ways to handle Ctrl+C?

Edit: Note that this is not the same question as the one linked in the comments, as I want to be able to execute some code to handle resources, instead of maintaining the data. Of course, maintaining the data allows for manual resource handling, but that is very inconvenient and will be very bad for my productivity during certain stages of development.

Oebele
  • 581
  • 1
  • 4
  • 17
  • 2
    I think you may be looking for something like [this](http://stackoverflow.com/questions/19005931/in-matlab-is-it-possible-to-terminate-a-script-but-save-all-its-internal-varia). – craigim Nov 10 '14 at 16:49
  • I had not found that question. There is one main difference with mine though - he wants to maintain data, while I want to be able to run some resource handling code. With that solution I need to do that manually, which I would also be able to do after the script got terminated. Therefore the answer there is not really what I am looking for, though it is a really interesting feature regardless. I strongly fear that there is no good answer to my question though. – Oebele Nov 11 '14 at 08:44

0 Answers0