HowTo 'IFError' and skip

How do identify an error in order that I can skip and run alternative script.
I want to
if fprintf('\t%s\n',TPin{1,2}{:}) iserror("??? Cell contents reference from a non-cell array object.")
do A;
else
do B;
90% of the time no error will occur, so would I be better writing;
do fprintf('\t%s\n',TPin{1,2}{:});
iserror goto do alternative;
In any case how do I pick up the error and perform a switch in task.

 採用された回答

the cyclist
the cyclist 2011 年 12 月 2 日

2 投票

You want to use a "try ... catch" construct:
>> doc try

3 件のコメント

Scragmore
Scragmore 2011 年 12 月 2 日
Thanks have just read,
Just to simplify for myself to prove vague understanding.
'try' runs code/function if successful no action taken and resumes outside 'end'
'catch' errors within 'try' caught and alternative script or message can be executed.
the cyclist
the cyclist 2011 年 12 月 2 日
Yes
Scragmore
Scragmore 2011 年 12 月 2 日
Thanks both of you, just what the doctor ordered.
AD

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

製品

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by