X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 10 Nov 2013 12:05 PM by  anon
Error Handling
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
10 Nov 2013 12:05 PM
    I have a program that takes files from a directory and calls another procedure to do data manipulation on it. Sometimes the procedure being called throws an error, it is not always in the same place. This causes the program to stop and then I have to manually restart it remove the offending file from the directory. What I would like to happen is that if any error is throw the first program moves the file out of the directory and then starts on the next file in the directory. I have tried the catch, error_status way but this does not execute when the error is throw the program just stops. I am assuming there is a way to do this although I have not found anything online. Sorry if this a noob question but I inherited this code and I am not very familiar with IDL. Thanks for any help, Curt

    Deleted User



    New Member


    Posts:
    New Member


    --
    12 Nov 2013 03:53 PM
    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.
    You are not authorized to post a reply.