1 Download
Updated 28 Feb 2006
No License
Unfortunately, Matlab does not show the location of an error, when the error is rethrown in the catch clause of a try-catch block. This can be very frustrating, since the error can reside several levels deep into possibly unfamiliar code.
DISPERROR will display the error message of the last error, together with the error stack, complete with hyperlinks.
Example:
% function testdisperror
% try
% a=[1 2 3];
% b=a(4711); % Index error
% catch
% % possibly do some housekeeping here
% rethrow(lasterror);
% end
%
% >> testdisperror
% ??? Attempted to access a(4711); index out of bounds ...
%
% >> disperror
% ??? Attempted to access a(4711); index out of bounds ...
% Error in ==> testdisperror at 4
Jerker Wagberg (2021). disperror (https://www.mathworks.com/matlabcentral/fileexchange/10181-disperror), MATLAB Central File Exchange. Retrieved .
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Create scripts with code, output, and formatted text in a single executable document.
Malcolm, you are absolutely right. I would never had created, let alone posted my version, had I known about yours. The search function here at File Exchange makes it a bit hard to check for similar postings though. Do a search for "print error" and you'll see what I mean...
Anyhow, please accept my sincere apologies.
J Wagberg
PS. I'm refraining from spelling out my first name, as a test whether it is some kind of adult content filter that removes my reviews. I have yet to see a review of mine published here!
That link should have been: http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=9525&objectType=FILE
Works well, but seems pretty similar to this one:
<a href="http://www.mathworks.com/matlabcentral/fileexchange/loadCategory.do?objectId=115&objectType=Category">Printing MATLAB errors</a>