MATLAB Answers

How to make matlab show line of error in appdesigner

조회 수: 3(최근 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개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by