To ignore the data files with error and proceed in the code

조회 수: 5 (최근 30일)
Pooja
Pooja 2014년 9월 9일
답변: Reema Alhassan 2018년 7월 24일
I am using gunzip(filename) in a loop to unzip the .gz files. e.g.
for x=1:N f=gunzip(fil_nme); end;
But for some the files it give error as follow
Error using gunzip>gunzipwrite (line 202) Unexpected end of input stream when attempting to GUNZIP the file "I:\GOES_DATA\G13\RETSD_MODMD_G13_GEC_2010356_11_gfsTfg_regWfg".
Error in gunzip>gunzipEntries (line 122) names{k} = gunzipwrite(entries(k).file, outputDir, baseName, streamCopier);
Error in gunzip (line 64) names = gunzipEntries(entries, outputDir);
Error in GOES_IASI_retrieval (line 46) f=gunzip(fil_nme);
and the whole program stops for some value of x less than N. I am not sure if this is error of gunzip or some error in datafile. If this error is in data file, is there any way that the error files can be skipped in the loop and the code is compiled for all values for x till N. i.e. Is there any way that I need not to restart to code after removing the erroneous datafile.
Thanks in advance

채택된 답변

David Young
David Young 2014년 9월 9일
Use try and catch. Something like
for ...
try
gunzip ...
catch me
<test error, if it's significant rethrow it, otherwise ignore it>
end
end
  댓글 수: 3
Iain
Iain 2014년 9월 10일
"me" is a variable that contains the error properties of whatever caused it to go into the catch statement.
David Young
David Young 2014년 9월 10일
If you put nothing between catch and end, that will probably be OK most of the time. The effect is to ignore all errors that occur between try and catch. Sometimes, you want to distinguish between different kinds of error (e.g. a missing file as opposed to a numeric error) and then you use me, as Iain says, to find out what the error was and act accordingly.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Reema Alhassan
Reema Alhassan 2018년 7월 24일
Do you know why this error occurs ?

카테고리

Help CenterFile Exchange에서 Standalone Applications에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by