/usr/share/psychtoolbox-3/PsychDemos/ErrorCatchDemo.m is in psychtoolbox-3-common 3.0.11.20131230.dfsg1-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | function ErrorCatchDemo
%
% Show how to use try and catch to clean up after an error.
%
% 12/19/03 dhb Wrote it based on suggestion from Scott French.
% 10/10/06 rhh Edited it.
% 10/11/06 dhb Turn off warnings, use max screen.
try
% Enclose all your real code between try and catch.
% Removes the blue screen flash and minimize extraneous warnings.
oldVisualDebugLevel = Screen('Preference', 'VisualDebugLevel', 3);
oldSupressAllWarnings = Screen('Preference', 'SuppressAllWarnings', 1);
% Find out how many screens and use largest screen number.
whichScreen = max(Screen('Screens'));
Screen('OpenWindow', whichScreen);
error('Oops!');
% Clean up, although in this case we never get here.
Screen('CloseAll');
Screen('Preference', 'VisualDebugLevel', oldVisualDebugLevel);
Screen('Preference', 'SuppressAllWarnings', oldSupressAllWarnings);
catch
% If an error occurs, the catch statements executed. We restore as
% best we can and then rethrow the error so user can see what it was.
Screen('CloseAll');
Screen('Preference', 'VisualDebugLevel', oldVisualDebugLevel);
Screen('Preference', 'SuppressAllWarnings', oldSupressAllWarnings);
fprintf('We''ve hit an error.\n');
psychrethrow(psychlasterror);
fprintf('This last text never prints.\n');
end
|