onCleanup - do different things based on how you entered it.

3 ビュー (過去 30 日間)
Eric Sampson
Eric Sampson 2013 年 3 月 18 日
Hi, I've got a function where we want to run some code if there is an error, or a Ctl-C, but not if the function exits normally.
If I use try/catch, then Ctl-C doesn't end up in the catch. If I define an onCleanup, then it executes when the function exists normally (which we don't want).
Can you think of a way to handle this situation? Maybe using DBSTACK in the onCleanup to determine how it was entered or something...
Thanks, Eric

採用された回答

Walter Roberson
Walter Roberson 2013 年 3 月 18 日
Share a variable with the cleanup routine. Set the variable differently if the routine is exiting normally. Have the cleanup routine test the variable.
  1 件のコメント
Eric Sampson
Eric Sampson 2013 年 3 月 18 日
Thanks Walter. That should work, I'll give it a shot :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by