when combing OnCleanup with evalin, weird order of execution
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
This function is to print in cmd window that the function was executed and exited.
The expected outcome is :
1
$$$$$$-Entering [testPrologue]
2
$$$$$$-Leaving [testPrologue]
If the fucntion prologue is nested inside the main function, this was true.
However, if I remove the prologue function and make a new file using this fucniton, then print order changed:
1
$$$$$$-Entering [testPrologue]
$$$$$$-Leaving [testPrologue]
2
Why the "$$$$$$-Leaving" was printed earlier even when "2" has not been printed?
In order to make prologue an independent function, how can I modify it to make it work?
Thanks
function testPrologue
clc;
disp(1);
prologue;
disp(2);
%%
function prologue
aStr1 = ['disp(''$$$$$$-Entering testPrologue'');'];
aStr2 = ['onCleanup(@() disp(''$$$$$$-Leaving [testPrologue]''));'];
aStr = sprintf('%s\n%s',aStr1,aStr2);
evalin('caller',aStr);
end
end
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Error Handling dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!