Calling the error function does not print the line number in r2022b

11 views (last 30 days)
In r2021a I can generate an error inside a function and the error message will be printed in the Command Window along with the stack trace and relevant line numbers:
error behavior in r2021a
In r2022b, the stack trace is displayed with the error line number on the caller script, but the line number error is not displayed on the callee script:
error behavior in r2022b
Please review this behavior and fix in upcoming updates.

Answers (1)

Rik on 29 Sep 2022
I personally use my own customized versions of error and warning. They take an options struct as the first argument to determine where the message should be printed.
options = struct('fid',1); % Print to command window.
this is a function [2022-09-29 07:37:44] Error: This generates an error > In a_test (line 3) In call_a_test (line 2) In LiveEditorEvaluationHelperEeditorId (line 2) In fevalMatlab (line 0) In fevalJSON (line 0)
Error using a_test
This generates an error

Error in call_a_test (line 2)

Error in solution (line 2)
The intention is that the printed text is stable across all versions of Matlab and Octave. I know this is not exactly the solution you're looking for, but it might be useful to you nonetheless.
(Note that what you perceive as a bug might be an intentional design choice you disagree with.)
Rik on 29 Sep 2022
I will probably publish these functions to the file exchange at some point. If and when I do, there will be a test matrix included. It is indeed my goal to cover every version since Matlab 6.5 (which is 20 years old by now).
If my answer helped you, please consider marking it as accepted answer.
I don't know if you can expect a staff member to comment, unless you contact support explicitly. Most comments posted by staff members are posted under their own capacity, not as an official statement from Mathworks.

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!

Translated by