Re: on_ioerror? [message #11883] |
Thu, 04 June 1998 00:00 |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Stein Vidar Hagfors Haugan (steinhh@ulrik.uio.no) writes in
reply to one of my more elegant programming efforts:
>> This is pseudo code, of course. :-)
>
> Nope. That was spaghetti, not pseudo.... :-)
> Jumping out of and then back into FOR loops gives me
> goosebumps.
Stein Vidar is right, of course. I was going to forego
the code entirely because I only had 10 minutes before
I had to pick up the kids, but I though, "Nah, piece of
cake."
But then I got shaken by having to do two things in the
same piece of code. Yikes! Since I've become infatuated
with object programming I've become a one-piece-of-code-
for-one-specific-thing kind of a guy. I just completely
forgot how to write that one-size-fits-all type of code.
My humble apologies. :-)
Cheers,
David
-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: on_ioerror? [message #11885 is a reply to message #11883] |
Thu, 04 June 1998 00:00  |
steinhh
Messages: 260 Registered: June 1994
|
Senior Member |
|
|
David Fanning wrote:
> This is pseudo code, of course. :-)
Nope. That was spaghetti, not pseudo.... :-)
Jumping out of and then back into FOR loops gives me
goosebumps.
FOR j=0,n DO BEGIN
catch,error
IF error NE 0 THEN BEGIN
print,!Err_String
goto,CONTINUE_GIF
ENDIF
read_gif,....
CONTINUE_GIF:
ENDFOR
catch,/cancel ;; A matter of purity..
FOR j=0,n DO BEGIN
catch,error
IF error NE 0 THEN BEGIN
print,!Err_String
goto,CONTINUE_TIFF
ENDIF
read_tiff,....
CONTINUE_TIFF:
ENDFOR
catch,/cancel ;; A matter of purity..
Regards,
Stein Vidar
|
|
|
Re: on_ioerror? [message #11891 is a reply to message #11883] |
Wed, 03 June 1998 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Dallas Masters (dallas@lanl.gov) writes:
> I'm running read_gif and read_tiff in a loop.
> If an I/O error occurs, I want to print an error message
> and continue going through the loop. Given read_gif
> and read_tiff, how would this be done (I've tried, nothing
> works yet). Thanks.
I just looked at the code for these two routines and both
return to the caller of the program when an error occurs
(ON_ERROR, 2). I should think a simple CATCH in the routine
that called either one of these programs would catch
errors. Then you could proceed in whatever manner seemed
appropriate.
Your code might look like this:
Catch, error
IF error NE 0 THEN BEGIN
Print, !Err_String
CASE loopFlag OF
1: GOTO, GIF_LOOP
2: GOTO, TIFF_LOOP
ENDCASE
ENDIF
loopFlag = 1
GIF_LOOP:
FOR j=0,n, DO READ_GIF, ....
loopFlag = 2
TIFF_LOOP:
for j=0, n DO READ_TIFF, ...
This is pseudo code, of course. :-)
Cheers,
David
-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|