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 ...@@ -156,7 +156,7 @@ while counter<100
gtCopy(fnamein, fnameout, fnameout_orig, parameters, move_data_flag); gtCopy(fnamein, fnameout, fnameout_orig, parameters, move_data_flag);
found=1; found=1;
catch mexc catch mexc
if strfind(mexc.identifier, 'EDF:') == 1 if gtCheckExceptionType(mexc, 'EDF:')
message = [ 'Skipping badly formed file: "' fnamein ... message = [ 'Skipping badly formed file: "' fnamein ...
'" (' mexc.identifier ')']; '" (' mexc.identifier ')'];
gtPrintException(mexc, message); gtPrintException(mexc, message);
......
...@@ -233,9 +233,8 @@ xmlfname=fullfile(parameters.acq.collection_dir,[parameters.acq.name '.xml']); ...@@ -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 to read the .xml file that may be present
try try
params_xml = gtLoadAcquisitionXML(xmlfname,interactive); params_xml = gtLoadAcquisitionXML(xmlfname,interactive);
catch Mexc catch mexc
if strcmp(Mexc.identifier, 'XML:no_xml_file') if gtCheckExceptionType(mexc, 'XML:no_xml_file', @()disp('Quitting..'))
disp('Quitting..')
return; return;
end end
end end
...@@ -336,8 +335,8 @@ try ...@@ -336,8 +335,8 @@ try
if strcmpi(parameters.acq.type, '360degree') if strcmpi(parameters.acq.type, '360degree')
gtDBCreateSpotPairTable(parameters.acq.name, 0, 0); gtDBCreateSpotPairTable(parameters.acq.name, 0, 0);
end end
catch Mexc catch mexc
gtPrintException(Mexc, 'failed to set up tables! try again, forcing overwite of existing tables?') gtPrintException(mexc, 'failed to set up tables! try again, forcing overwite of existing tables?')
check=inputwdefault('Overwrite tables? [y/n]', 'n'); check=inputwdefault('Overwrite tables? [y/n]', 'n');
if strcmpi(check,'y') if strcmpi(check,'y')
gtDBCreateDifblobTable(parameters.acq.name, 1); gtDBCreateDifblobTable(parameters.acq.name, 1);
......
...@@ -61,12 +61,10 @@ function [img, varargout] = edf_wait_read(fname, bb, waitfortranslated) ...@@ -61,12 +61,10 @@ function [img, varargout] = edf_wait_read(fname, bb, waitfortranslated)
end end
pause(2) pause(2)
end end
catch Mexc catch mexc
gtPrintException(Mexc, 'EDF access failed.') gtPrintException(mexc, 'EDF access failed.')
% just try again % Just try again (we shouldn't rely on this)
% if strfind(Mexc.identifier, 'EDF:') == 1 % gtCheckExceptionType(mexc, 'EDF:', @()rethrow(mexc));
% rethrow(Mexc)
% end
disp(' - trying again') disp(' - trying again')
pause(1) pause(1)
end %try - sometimes file acess fails because of simultaneous read / write access... 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) ...@@ -82,13 +80,10 @@ function [img, varargout] = edf_wait_read(fname, bb, waitfortranslated)
img = edf_read(fname, bb ,'nodisp', info); img = edf_read(fname, bb ,'nodisp', info);
end end
break break
catch Mexc catch mexc
gtPrintException(Mexc, 'EDF Read failed.') gtPrintException(mexc, 'EDF Read failed.')
% just try again % Just try again (we shouldn't rely on this)
% if strfind(Mexc.identifier, 'EDF:') == 1 % gtCheckExceptionType(mexc, 'EDF:', @()rethrow(mexc));
% rethrow(Mexc)
% end
lasterr
disp(' - trying again') disp(' - trying again')
pause(1) pause(1)
end 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 ...@@ -7,8 +7,8 @@ try
mcc_vers_minor = str2double(mcc_vers{1}{2}); mcc_vers_minor = str2double(mcc_vers{1}{2});
mcc_vers_major = str2double(mcc_vers{1}{1}); mcc_vers_major = str2double(mcc_vers{1}{1});
compiled_fine = true; % In case of error, we will re modify it compiled_fine = true; % In case of error, we will re modify it
catch Mexc catch mexc
gtPrintException(Mexc, 'Error: Is the Matlab Compiler installed?') gtPrintException(mexc, 'Error: Is the Matlab Compiler installed?')
compiled_fine = false; compiled_fine = false;
return return
end end
...@@ -40,13 +40,13 @@ delete(filemask); ...@@ -40,13 +40,13 @@ delete(filemask);
fprintf('- Placing result in %s\n', path_for_binaries); fprintf('- Placing result in %s\n', path_for_binaries);
try try
mcc('-m', myfunctionname, '-d', path_for_binaries); mcc('-m', myfunctionname, '-d', path_for_binaries);
catch Mexc catch mexc
if strfind(Mexc.identifier, 'mcc_err_checkout_failed') if gtCheckExceptionType(mexc, 'mcc_err_checkout_failed')
disp('Could not get a compiler license.') disp('Could not get a compiler license.')
disp('Surf to http://compweb/public/nice/matlab_licence.php') 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!') disp('and call the person with the compiler license to see if you could use it!')
else else
gtPrintException(Mexc); gtPrintException(mexc);
end end
compiled_fine = false; compiled_fine = false;
return return
...@@ -65,8 +65,8 @@ if ( mcc_vers_major < 4 || (mcc_vers_major == 4 && mcc_vers_minor < 8)) ...@@ -65,8 +65,8 @@ if ( mcc_vers_major < 4 || (mcc_vers_major == 4 && mcc_vers_minor < 8))
getenv('ARCH'), ctfname); getenv('ARCH'), ctfname);
try try
[status, result] = unix(cmd); [status, result] = unix(cmd);
catch Mexc catch mexc
gtPrintException(Mexc, 'Extraction of archive did not work') gtPrintException(mexc, 'Extraction of archive did not work')
end end
if status ~= 0 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