In a lot of our programming work we need to clean up (delete temp files, change file permissions, release disabled GUI controls, etc) after our functions if it quits successfully, unexpectedly or by the 'return' keyword.
Is there syntax similar to the functionality in a C++ Object Destructor? Similar to the following destructor block (hence 'destruct' becomes a keyword in MATLAB functions):
function foo(...) % Main program goes here
destruct % Cleanup routines
end
For any reason the function quits (errors, 'return', or reached the end), the contents of the destructor/finally block will be executed.
Best Answer