File: ple.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (65 lines) | stat: -rw-r--r-- 2,168 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function ple(s)
% PLE "Print Last Error"
%
% ple prints the last error message issued by Matlab, including a complete
% backtrace of the call-sequence of functions that led to the error
% condition. Each line in the backtrace includes M-Filename and line number
% and allows you to open that file on the specified line by simply clicking
% on it with the mouse.
%
% ple is only supported on Matlab version 7 (Release 14 service pack 3) and later.
%
% Usage:
% ple     - Print last error, as contained in error structure 'psychlasterror'.
% ple(s)  - Print error and backtrace contained in error structure 's'.
%
% Copyright: This implementation of 'ple' is a slightly modified derivate of
% the original public domain implementation of ple.m by Malcolm Wood (the MathWorks).
%
% The original file can be downloaded from Matlab Central at:
% http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=
% 9525&objectType=file
%
% Thanks to David Fencsik for pointing us to this useful file and Malcolm
% Wood for writing it.
%

% History:
% 10/17/06 Derived from ple.m by MK.

% Error structure s provided?
if nargin<1
    % No. Fetch it from psychlasterror.
    s = psychlasterror;
end

if isempty(s.message)
   fprintf(1,'No error message stored\n');
   return;
end

fprintf(1,'Last Error: %s (%s)\n',s.message,s.identifier);

% Do we have a stack? This is a field or property.
if (isstruct(s) && ~isfield(s, 'stack')) || (isobject(s) && ~isprop(s, 'stack'))
    % Nope. This is not Matlab 7 or later. We're done.
    fprintf(1,'Error message does not contain a stack.\n');
    return;
end

% Stack available. Pretty print a nice backtrace.
for i=1:numel(s.stack)
   e = s.stack(i);
   ff = which(e.file);
   [ignore_dir,command] = fileparts(ff);
   n = e.name;
   href = sprintf('matlab:opentoline(''%s'',%d)',ff,e.line);
   if strcmp(command,n)
       % main function in this file
       fprintf(1,'    <a href="%s">%s,%d</a>\n',href,ff,e.line);
   else
       % subfunction in this file
       fprintf(1,'    <a href="%s">%s >%s,%d</a>\n',href,ff,n,e.line);
   end
end
fprintf(1,'\n');