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

Home » Public Forums » archive » CATCH inside a FOR loop and out?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
CATCH inside a FOR loop and out? [message #88322] Mon, 14 April 2014 12:25 Go to previous message
cgguido is currently offline  cgguido
Messages: 195
Registered: August 2005
Senior Member
Say I want to catch two kinds of erros:

1. if error happens inside a for loop I want to deal with it and then continue with i++
2. if error happens outside the loop I want to return -1

Can this be done?

Thanks,
Gianguido


Here is what I got, which catches erros inside the loop and behaves like I want it to, but I would like to deal with ;NEWERROR differently...


;;--------------------
PRO proerrortest

compile_opt idl2


a = 10*(indgen(10)+1)
FOR i = 0, 9 DO BEGIN
CATCH, Error_status
IF Error_status NE 0 THEN BEGIN
CATCH, /CANCEL
PRINT, 'GCError index: ', Error_status
PRINT, 'GCError message: ', !ERROR_STATE.MSG
i++
if i gt 9 then return
ENDIF


IF i EQ 3 THEN print, i, a[100]
IF i EQ 7 THEN print, i, a[100]
IF i NE 3 AND i NE 7 THEN print, i, a[i]
ENDFOR


;NEWERROR

RETURN
END
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: DLM "unload"?
Next Topic: traces plot outside of x-axis boundaries

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

Current Time: Wed Oct 08 15:11:57 PDT 2025

Total time taken to generate the page: 0.00473 seconds