comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: error reading file question
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: error reading file question [message #51196 is a reply to message #51194] Tue, 07 November 2006 12:36 Go to previous messageGo to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
David Fanning wrote:
> Paul van Delst writes:
>
>> pro test
>> ; Setup error handler
>> catch, ierr
>> if(ierr ne 0)then begin
>> catch, /cancel
>> message, !error_state.msg + '; Closing file...', /continue
>> if(n_elements(fileid) ne 0) then free_lun, fileid
>> return
>> endif
>> ; Read non-existant file
>> openr, fileid, 'newfile.dat', /get_lun
>> x=0.0
>> readu, fileid, x
>> free_lun, fileid
>> print, x
>> catch,/cancel ; <--- don't forget this
>> end
>
> I wouldn't worry about forgetting to cancel
> the Catch in the next to last line. CATCH
> is only in effect for that program module
> anyway, and you are, uh, about to leave
> there. :-)

Is that true? I could be wrong, but I recall some sort of issue with not canceling the
CATCH before leaving the routine...somehow it was still active. Or something. You know....
ehem.

> Cheers,
>
> David
>
> P.S. You *should* cancel the CATCH in the first
> line of the error handling code, though, because--
> Heaven forbid!--if you have an error in your error
> handling code you are going to notice!! :-)

Yes. Hello infinite loopage. Modifiying the above to:

pro test
catch, ierr
if(ierr ne 0)then begin
catch, /cancel
message, !error_state.msg + '; Closing file...', /continue
free_lun, fileid
return
endif
message, 'a pretend error!',/noname,/noprint
openr, fileid, 'newfile.dat', /get_lun
x=0.0
readu, fileid, x
free_lun, fileid
print, x
end

gives me:

IDL> .run test
% Compiled module: TEST.
IDL> test
% TEST: a pretend error!; Closing file...
% FREE_LUN: Variable is undefined: FILEID.
% Execution halted at: TEST 6 /export/lnx374/wd20pd/scratch/test.pro
% $MAIN$

Commenting out the catch,/cancel in the error handler portion gives:

IDL> .run test
% Compiled module: TEST.
IDL> test
% TEST: a pretend error!; Closing file...
% TEST: FREE_LUN: Variable is undefined: FILEID.; Closing file...
% TEST: FREE_LUN: Variable is undefined: FILEID.; Closing file...
% TEST: FREE_LUN: Variable is undefined: FILEID.; Closing file...
% TEST: FREE_LUN: Variable is undefined: FILEID.; Closing file...
% TEST: FREE_LUN: Variable is undefined: FILEID.; Closing file...
% TEST: FREE_LUN: Variable is undefined: FILEID.; Closing file...
% TEST: FREE_LUN: Variable is undefined: FILEID.; Closing file...
% TEST: FREE_LUN: Variable is undefined: FILEID.; Closing file...
% TEST: FREE_LUN: Variable is undefined: FILEID.; Closing file...
% TEST: FREE_LUN: Variable is undefined: FILEID.; Closing file...
% TEST: FREE_LUN: Variable is undefined: FILEID.; Closing file...
% TEST: FREE_LUN: Variable is undefined: FILEID.; Closing file...
% TEST: FREE_LUN: Variable is undefined: FILEID.; Closing file...
% TEST: FREE_LUN: Variable is undefined: FILEID.; Closing file...
% TEST: FREE_LUN: Variable is undefined: FILEID.; Closing file...
% TEST: FREE_LUN: Variable is undefined: FILEID.; Closing file...
% TEST: FREE_LUN: Variable is undefined: FILEID.; Closing file...
....etc. ad infinitum.

paulv

--
Paul van Delst Ride lots.
CIMSS @ NOAA/NCEP/EMC Eddy Merckx
Ph: (301)763-8000 x7748
Fax:(301)763-8545
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Printing problem as RGB in Linux
Next Topic: 3D plotting

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 11:15:57 PDT 2025

Total time taken to generate the page: 1.12385 seconds