Skip to content
Snippets Groups Projects
Commit c74241a7 authored by Nicola Vigano's avatar Nicola Vigano
Browse files

Exceptions: added a type checker for the exception types.


It can even execute actions if a function handle is passed

Signed-off-by: default avatarNicola Vigano <nicola.vigano@esrf.fr>

Conflicts:

	zUtil_EDF/edf_wait_read.m

git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@493 4c865b51-4357-4376-afb4-474e03ccb993
parent 3dbfb3b9
No related branches found
No related tags found
No related merge requests found
......@@ -156,7 +156,7 @@ while counter<100
gtCopy(fnamein, fnameout, fnameout_orig, parameters, move_data_flag);
found=1;
catch mexc
if strfind(mexc.identifier, 'EDF:') == 1
if gtCheckExceptionType(mexc, 'EDF:')
message = [ 'Skipping badly formed file: "' fnamein ...
'" (' mexc.identifier ')'];
gtPrintException(mexc, message);
......
......@@ -233,9 +233,8 @@ xmlfname=fullfile(parameters.acq.collection_dir,[parameters.acq.name '.xml']);
% try to read the .xml file that may be present
try
params_xml = gtLoadAcquisitionXML(xmlfname,interactive);
catch Mexc
if strcmp(Mexc.identifier, 'XML:no_xml_file')
disp('Quitting..')
catch mexc
if gtCheckExceptionType(mexc, 'XML:no_xml_file', @()disp('Quitting..'))
return;
end
end
......@@ -336,8 +335,8 @@ try
if strcmpi(parameters.acq.type, '360degree')
gtDBCreateSpotPairTable(parameters.acq.name, 0, 0);
end
catch Mexc
gtPrintException(Mexc, 'failed to set up tables! try again, forcing overwite of existing tables?')
catch mexc
gtPrintException(mexc, 'failed to set up tables! try again, forcing overwite of existing tables?')
check=inputwdefault('Overwrite tables? [y/n]', 'n');
if strcmpi(check,'y')
gtDBCreateDifblobTable(parameters.acq.name, 1);
......
......@@ -61,12 +61,10 @@ function [img, varargout] = edf_wait_read(fname, bb, waitfortranslated)
end
pause(2)
end
catch Mexc
gtPrintException(Mexc, 'EDF access failed.')
% just try again
% if strfind(Mexc.identifier, 'EDF:') == 1
% rethrow(Mexc)
% end
catch mexc
gtPrintException(mexc, 'EDF access failed.')
% Just try again (we shouldn't rely on this)
% gtCheckExceptionType(mexc, 'EDF:', @()rethrow(mexc));
disp(' - trying again')
pause(1)
end %try - sometimes file acess fails because of simultaneous read / write access...
......@@ -82,13 +80,10 @@ function [img, varargout] = edf_wait_read(fname, bb, waitfortranslated)
img = edf_read(fname, bb ,'nodisp', info);
end
break
catch Mexc
gtPrintException(Mexc, 'EDF Read failed.')
% just try again
% if strfind(Mexc.identifier, 'EDF:') == 1
% rethrow(Mexc)
% end
lasterr
catch mexc
gtPrintException(mexc, 'EDF Read failed.')
% Just try again (we shouldn't rely on this)
% gtCheckExceptionType(mexc, 'EDF:', @()rethrow(mexc));
disp(' - trying again')
pause(1)
end
......
function got_it = gtCheckExceptionType(mexc, type, action)
% GTCHECKEXCEPTIONTYPE Checks the type of the exception, and if requested
% performs an action.
% Input:
% mexc - the exception
% type - the type to check (can be a regular expression)
% action - function handle to perform in case of match
got_it = ~isempty(regexp(mexc.identifier, type, 'once'));
if (got_it && exist('action', 'var') && isa(action, 'function_handle'))
action();
end
end
......@@ -7,8 +7,8 @@ try
mcc_vers_minor = str2double(mcc_vers{1}{2});
mcc_vers_major = str2double(mcc_vers{1}{1});
compiled_fine = true; % In case of error, we will re modify it
catch Mexc
gtPrintException(Mexc, 'Error: Is the Matlab Compiler installed?')
catch mexc
gtPrintException(mexc, 'Error: Is the Matlab Compiler installed?')
compiled_fine = false;
return
end
......@@ -40,13 +40,13 @@ delete(filemask);
fprintf('- Placing result in %s\n', path_for_binaries);
try
mcc('-m', myfunctionname, '-d', path_for_binaries);
catch Mexc
if strfind(Mexc.identifier, 'mcc_err_checkout_failed')
catch mexc
if gtCheckExceptionType(mexc, 'mcc_err_checkout_failed')
disp('Could not get a compiler license.')
disp('Surf to http://compweb/public/nice/matlab_licence.php')
disp('and call the person with the compiler license to see if you could use it!')
else
gtPrintException(Mexc);
gtPrintException(mexc);
end
compiled_fine = false;
return
......@@ -65,8 +65,8 @@ if ( mcc_vers_major < 4 || (mcc_vers_major == 4 && mcc_vers_minor < 8))
getenv('ARCH'), ctfname);
try
[status, result] = unix(cmd);
catch Mexc
gtPrintException(Mexc, 'Extraction of archive did not work')
catch mexc
gtPrintException(mexc, 'Extraction of archive did not work')
end
if status ~= 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment