フィルターのクリア

How to make matlab show line of error in appdesigner

5 ビュー (過去 30 日間)
Noah Kilps
Noah Kilps 2020 年 11 月 11 日
コメント済み: Noah Kilps 2020 年 11 月 11 日
Hello,
I have created an app, and in my code it creates a message box when there is an error.
try
% A bunch of lines of code
catch ME2
if (strcmp(ME2.identifier,'MATLAB:catenate:dimensionMismatch'))
msg2 = ['An error was found in this loop'];
causeException2 = MException('MATLAB:myCode:dimensions',msg2);
ME2 = addCause(ME2, causeException2); % this is the error that would stop the code
else
end
disp(ME2) % we are displaying the error so that we can still identify the problem if we have an error
msgbox(['MAINTENANCE NEEDED. CONTACT SHOKEN MODE. ' ME2.message ' See line ' sprintf('%g', ME2.stack.line) '.'],'FYI') % informs the auditor which file failed the loop
end
I want the message box to say what line the error occurred. It works perfectly fine when I run this script not as an app. In app designer I get this weird result where the line number (713300??) should be:
Is it possible for appdesigner to tell me what line the error was at?

採用された回答

Jon
Jon 2020 年 11 月 11 日
編集済み: Jon 2020 年 11 月 11 日
I see in the documentation that "stack is an N-by-1 struct array, where N represents the depth of the call stack"
Is it possible that you need to further index
sprintf('%g', ME2.stack.line)
maybe
sprintf('%g', ME2.stack(1).line)
In any case I would suggest going in with the debugger and setting a break point on the line where the anaomolous line number is printed and investigate exactly what is in ME2.stack and while you are in there experiment on the command line to see how to get it to print out properly
  1 件のコメント
Noah Kilps
Noah Kilps 2020 年 11 月 11 日
The further indexing worked!!!

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by