How to make matlab show line of error in appdesigner

7 views (last 30 days)
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?

Accepted Answer

Jon
Jon on 11 Nov 2020
Edited: Jon on 11 Nov 2020
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

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!