Forum Post: RE: Catch not working as expected

  • Thread starter Thread starter cverbiest
  • Start date Start date
Status
Not open for further replies.
C

cverbiest

Guest
I think this is a combination of no-undo and buffer scoping. NO-UNDO causes the error not to be undo. when the procedure ends the buffer goes out of scope and you get the error again. ROUTINE-LEVEL ON ERROR UNDO, THROW. session:appl-alert = yes. session:system-alert = yes. session:debug-alert = yes. DEFINE TEMP-TABLE ttTest NO-UNDO FIELD id AS CHARACTER FIELD test-name AS CHARACTER INDEX i-ttTest-1 IS PRIMARY UNIQUE id. createblock: DO ON ERROR UNDO, LEAVE: CREATE ttTest. ASSIGN ttTest.id = "1" ttTest.test-name = "2". validate ttTest. CREATE ttTest. ASSIGN ttTest.id = "1" ttTest.test-name = "2". validate ttTest. CATCH procerror AS Progress.Lang.Error: message "Inside catch". if procerror:getmessagenum(1) = 132 then delete ttTest. leave createblock. END CATCH. FINALLY: message "Inside finally" error-status:error. END FINALLY. end. message "Done". CATCH procerror AS Progress.Lang.Error: message "Inside catch 2" procerror:getmessage(1). leave. END CATCH. 2nd cleaner solution with strong scoping ROUTINE-LEVEL ON ERROR UNDO, THROW. session:appl-alert = yes. session:system-alert = yes. session:debug-alert = yes. DEFINE TEMP-TABLE ttTest NO-UNDO FIELD id AS CHARACTER FIELD test-name AS CHARACTER INDEX i-ttTest-1 IS PRIMARY UNIQUE id. createblock: DO ON ERROR UNDO, LEAVE: do for ttTest: /* strong scope */ CREATE ttTest. ASSIGN ttTest.id = "1" ttTest.test-name = "2". validate ttTest. CREATE ttTest. ASSIGN ttTest.id = "1" ttTest.test-name = "2". validate ttTest. end. CATCH procerror AS Progress.Lang.Error: message "Inside catch" procerror:getmessage(1). END CATCH. FINALLY: message "Inside finally" error-status:error. END FINALLY. end. message "Done". CATCH procerror AS Progress.Lang.Error: message "Inside catch 2" procerror:getmessage(1). leave. END CATCH.

Continue reading...
 
Status
Not open for further replies.
Back
Top