4.0

4.0 | 1 rating Rate this file 9 downloads (last 30 days) File Size: 2.74 KB File ID: #10181

disperror

by Jerker Wagberg

 

27 Feb 2006 (Updated 28 Feb 2006)

No BSD License  

Display latest error message and where the error occured.

Download Now | Watch this File

File Information
Description

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

MATLAB release MATLAB 7.1.0 (R14SP3)
Other requirements Uses undocumented Matlab function OPENTOLINE.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
01 Mar 2006 Malcolm Wood

Works well, but seems pretty similar to this one:
<a href="http://www.mathworks.com/matlabcentral/fileexchange/loadCategory.do?objectId=115&objectType=Category"&gt;Printing MATLAB errors</a>

01 Mar 2006 Malcolm Wood

That link should have been: http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=9525&objectType=FILE

01 Mar 2006 J Wagberg

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!

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
development environment Jerker Wagberg 22 Oct 2008 08:17:09
error message rethrow try catch stack line Jerker Wagberg 22 Oct 2008 08:17:09
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com