MATLAB Answers

1

Display the error containing line in .m file

Horia 님이 질문을 제출함. 2 Aug 2011
Is there a method to display the error containing line in .m file, when the execution stops?

  댓글 수: 1

Your question sounds like:
How to pinpoint the line that errors in a "highlight some lines + F9"?

로그인 to comment.

답변 수: 3

Jan 님의 답변 2 Aug 2011

Perhaps you are looking for:
dbstop if error
or if you want to catch error inside TRY-CATCH also:
dbstop if all error
[EDITED]: In modern Matlab versions this is documented:
dbstop if caught error
Then the failing line is highlighted in the editor automatically.

  댓글 수: 8

표시 이전 댓글 수: 5
R2011a:
dbstop in file
dbstop in file at location
dbstop in file if expression
dbstop in file at location if expression
dbstop if condition
dbstop(s)
Mathworks seems to love play "hide and seek", until they come with another release...
Anyways: 'dbstop if all error' works nevertheles on 2011a
But no longer appearing in "Help".

로그인 to comment.


Fangjun Jiang 님의 답변 2 Aug 2011

It is usually indicated in the error message.
Also, help dbstack.

  댓글 수: 5

표시 이전 댓글 수: 2
The standard error message traceback shows not only any chain of library calls, but also the line in the user .m file
Jan 3 Aug 2011
Under which circumstances does it (MATLAB?) show "error at" without a line number? Usually a line number is following.
The line number in the function or library used by Matlab, but not the one in the .m file.

로그인 to comment.


Paulo Silva 님의 답변 2 Aug 2011

After you get the error, execute this
l=lasterror;
fprintf('The last error was on line %d of the file called %s \n',...
l.stack.line,l.stack.name)

  댓글 수: 1

I get an empty stack if in a new .m file:
s = s(1)
l = lasterror

로그인 to comment.



Translated by