I wonder if maybe you have a "CATCH, /CANCEL" call in your CATCH block. If this is the case, then the CATCH statement might be executed the first error you encounter but not execute the second time your program experiences an error. Therefore, if you have "CATCH, /CANCEL" in you CATCH block, it might be executing code in the CATCH block for your first failed file but then throwing the error on the second file. Below, I have modified the CATCH_EXAMPLE program provided on the CATCH help page (
http://exelisvis.com/docs/CATCH.html) to demonstrate this:
;************************ BEGIN PROGRAM**************************************
PRO CATCH_EXAMPLE, CAN=CAN
n_elm = 10
; Define variable A:
A = FLTARR(n_elm)
; Establish error handler. When errors occur, the index of the
; error is returned in the variable Error_status:
CATCH, Error_status
;This statement begins the error handler:
IF Error_status NE 0 THEN BEGIN
PRINT, 'Error index: ', Error_status
PRINT, 'Error message: ', !ERROR_STATE.MSG
; Handle the error by extending A:
n_elm++
A=FLTARR(n_elm)
if KEYWORD_SET(CAN) then begin
CATCH, /CANCEL
endif
ENDIF
; Cause an error:
A[11]=12
; Even though an error occurs in the line above, program
; execution continues to this point because the event handler
; extended the definition of A so that the statement can be
; re-executed.
HELP, A
END
;************************** END PROGRAM****************************************
Without the example the "CATCH, /CANCEL statement the program will execute the CATCH statement as many times as needed to correct the error:
IDL> CATCH_EXAMPLE
Error index: -162
Error message: Attempt to subscript A with is out of range.
Error index: -162
Error message: Attempt to subscript A with is out of range.
A FLOAT = Array[12]
If you use the "CATCH, /CANCEL" call, the CATCH block will only be called once and then it will stop executing on the next error.
IDL> CATCH_EXAMPLE, /can
Error index: -162
Error message: Attempt to subscript A with is out of range.
% Attempt to subscript A with is out of range.
% Execution halted at: CATCH_EXAMPLE 36 C:\Users\dstarbuck\catch_example.pro
% $MAIN$
I hope that this information might be helpful.